Skip to content

Fix #93 context deadline exceeded #94

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

Merged
merged 1 commit into from
May 24, 2025
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
16 changes: 12 additions & 4 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func PkgInfo(w io.Writer, res ddao.GetSingleResultRow) {
var wg sync.WaitGroup
wg.Add(len(stages))

// Create a context with a 2-second timeout
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
// Create a context with a 3-second timeout
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

// Fetch URLs in parallel
Expand All @@ -196,15 +196,23 @@ func PkgInfo(w io.Writer, res ddao.GetSingleResultRow) {
req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil)
if err != nil {
results[index].StatusCode = http.StatusInternalServerError
results[index].Error = err.Error()
if err == context.DeadlineExceeded {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be errors.Is.

results[index].Error = "Request timed out. The server is taking too long to respond. Use the link above to access original log file."
} else {
results[index].Error = err.Error()
}
return
}

// Make the request
resp, err := http.DefaultClient.Do(req)
if err != nil {
results[index].StatusCode = http.StatusInternalServerError
results[index].Error = err.Error()
if err == context.DeadlineExceeded || err.Error() == "context deadline exceeded" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that with errors.Is, the second clause won't be needed, as this will fire even for a wrapped DeadlineExceeded.

results[index].Error = "Request timed out. The server is taking too long to respond. Use the link above to access original log file."
} else {
results[index].Error = err.Error()
}
return
}
defer resp.Body.Close()
Expand Down
Loading