Skip to content

Commit ac5b997

Browse files
committed
Prevent context deadline error propagation in GetCommitsInfo
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` or if it could be unwrapped to one. Fix go-gitea#20329 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 966e7bd commit ac5b997

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

modules/git/log_name_status.go

Lines changed: 5 additions & 3 deletions
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 err == context.DeadlineExceeded || errors.Unwrap(err) == context.DeadlineExceeded {
358360
break heaploop
359361
}
360362
g.Close()

0 commit comments

Comments
 (0)