From 058457010c818b3ccb24d2329a921956577de2b9 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 4 May 2023 15:19:25 +0800 Subject: [PATCH 1/2] fix: check log indexes length --- routers/web/repo/actions/view.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index f96cd2acf815f..d8fb7ac448508 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -209,8 +209,18 @@ func ViewPost(ctx *context_module.Context) { step := steps[cursor.Step] logLines := make([]*ViewStepLogLine, 0) // marshal to '[]' instead fo 'null' in json - if c := cursor.Cursor; c < step.LogLength && c >= 0 { - index := step.LogIndex + c + + index := step.LogIndex + cursor.Cursor + validCursor := cursor.Cursor >= 0 && + // !(cursor.Cursor < step.LogLength) when the frontend tries to fetch next line before it's ready. + // So return the same cursor and empty lines to let the frontend retry. + cursor.Cursor < step.LogLength && + // !(index < task.LogIndexes[index]) when task data is older than step data. + // It can be fixed by making sure write/read tasks and steps in the same transaction, + // but it's easier to just treat it as fetching the next line before it's ready. + index < task.LogIndexes[index] + + if validCursor { length := step.LogLength - cursor.Cursor offset := task.LogIndexes[index] var err error From f7d318d8cf74e403887e2793c54192e7924a204e Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 4 May 2023 15:24:14 +0800 Subject: [PATCH 2/2] fix: typo --- routers/web/repo/actions/view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index d8fb7ac448508..c64b0fac394e5 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -218,7 +218,7 @@ func ViewPost(ctx *context_module.Context) { // !(index < task.LogIndexes[index]) when task data is older than step data. // It can be fixed by making sure write/read tasks and steps in the same transaction, // but it's easier to just treat it as fetching the next line before it's ready. - index < task.LogIndexes[index] + index < int64(len(task.LogIndexes)) if validCursor { length := step.LogLength - cursor.Cursor