Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check length of LogIndexes in case it is outdated #24516

Merged
merged 4 commits into from
May 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 < int64(len(task.LogIndexes))

if validCursor {
length := step.LogLength - cursor.Cursor
offset := task.LogIndexes[index]
var err error
Expand Down