mirror of
https://github.com/lukaszraczylo/ghtracker.git
synced 2026-10-14 00:58:36 +00:00
fix(web): keep the action status fetch alive when a client disconnects
The status fetch used the request context. A client that dropped the connection, such as a readiness probe with a one second timeout, cancelled the fetch. The failure was then cached and every later request showed no action status. The fetch now ignores the caller cancellation and keeps its own timeout.
This commit is contained in:
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log/slog"
|
||||
@@ -407,3 +408,15 @@ func TestRedirectDoesNotForwardToken(t *testing.T) {
|
||||
t.Fatal("bearer token forwarded across a redirect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusFetchSurvivesCancelledRequest(t *testing.T) {
|
||||
fh := newFakeHook(t)
|
||||
fh.statBody = `[{"repo":"o/r","url":"` + alertURL + `","state":"running"}]`
|
||||
h := newActionServer(t, nil, fh.srv.URL)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
rows, err := h.actions.statusRows(ctx, h.actions.list[0])
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("rows=%d err=%v, want the fetch to complete despite the cancelled request", len(rows), err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user