Skip to content

Commit 780b198

Browse files
6543zeripath
andauthored
Prevent context deadline error propagation in GetCommitsInfo (#20346) (#20361)
Backport #20346 Although `WalkGitLog` tries to test for `context.DeadlineExceededErr` there is a small chance that the error will propagate to the reader before it is recognised. This will cause the error to propagate up to `renderDirectoryFiles` and cause a http status 500. Here we check that the error passed is a `DeadlineExceededErr` via error.Is Fix #20329 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
1 parent f4e219f commit 780b198

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

modules/git/log_name_status.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bufio"
99
"bytes"
1010
"context"
11+
"errors"
1112
"io"
1213
"path"
1314
"sort"
@@ -62,9 +63,10 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p
6263
})
6364
if err != nil {
6465
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
65-
} else {
66-
_ = stdoutWriter.Close()
66+
return
6767
}
68+
69+
_ = stdoutWriter.Close()
6870
}()
6971

7072
// For simplicities sake we'll us a buffered reader to read from the cat-file --batch
@@ -354,7 +356,7 @@ heaploop:
354356
}
355357
current, err := g.Next(treepath, path2idx, changed, maxpathlen)
356358
if err != nil {
357-
if err == context.DeadlineExceeded {
359+
if errors.Is(err, context.DeadlineExceeded) {
358360
break heaploop
359361
}
360362
g.Close()

0 commit comments

Comments
 (0)