Skip to content

Commit 27a5696

Browse files
authored
Check length of LogIndexes in case it is outdated (#24516)
Fix #24458
1 parent 78fdbaf commit 27a5696

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

routers/web/repo/actions/view.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,18 @@ func ViewPost(ctx *context_module.Context) {
209209
step := steps[cursor.Step]
210210

211211
logLines := make([]*ViewStepLogLine, 0) // marshal to '[]' instead fo 'null' in json
212-
if c := cursor.Cursor; c < step.LogLength && c >= 0 {
213-
index := step.LogIndex + c
212+
213+
index := step.LogIndex + cursor.Cursor
214+
validCursor := cursor.Cursor >= 0 &&
215+
// !(cursor.Cursor < step.LogLength) when the frontend tries to fetch next line before it's ready.
216+
// So return the same cursor and empty lines to let the frontend retry.
217+
cursor.Cursor < step.LogLength &&
218+
// !(index < task.LogIndexes[index]) when task data is older than step data.
219+
// It can be fixed by making sure write/read tasks and steps in the same transaction,
220+
// but it's easier to just treat it as fetching the next line before it's ready.
221+
index < int64(len(task.LogIndexes))
222+
223+
if validCursor {
214224
length := step.LogLength - cursor.Cursor
215225
offset := task.LogIndexes[index]
216226
var err error

0 commit comments

Comments
 (0)