detached 9faaf17

fix: context-aware sleep in TCP and HTTP probe retry loops

commit
9faaf179d80de282e73ff1c3cd86474252dff3fd
author
brice · · 2026-03-04 08:59 UTC
parent
935f0d1
signature
unsigned
1 file · +24 -2
M internal/usecase/container/readiness.go +24 -2
@@ -46,9 +46,20 @@ func tcpProbe(ctx context.Context, addr string, timeout time.Duration) error {
4646 log.Debug().Err(err).Str("addr", addr).Int("attempt", attempts).Msg("TCP probe attempt failed")
4747 }
4848
49+ sleepInterval := 500 * time.Millisecond
50+ if deadline, ok := ctx.Deadline(); ok {
51+ if rem := time.Until(deadline); rem < sleepInterval {
52+ sleepInterval = rem
53+ }
54+ }
55+ if sleepInterval <= 0 {
56+ return ctx.Err()
57+ }
58+ t := time.NewTimer(sleepInterval)
4959 select {
50- case <-time.After(500 * time.Millisecond):
60+ case <-t.C:
5161 case <-ctx.Done():
62+ t.Stop()
5263 return ctx.Err()
5364 }
5465 }
@@ -95,9 +106,20 @@ func httpProbe(ctx context.Context, url string, timeout time.Duration) error {
95106 }
96107 }
97108
109+ sleepInterval := time.Second
110+ if deadline, ok := ctx.Deadline(); ok {
111+ if rem := time.Until(deadline); rem < sleepInterval {
112+ sleepInterval = rem
113+ }
114+ }
115+ if sleepInterval <= 0 {
116+ return ctx.Err()
117+ }
118+ t := time.NewTimer(sleepInterval)
98119 select {
99- case <-time.After(time.Second):
120+ case <-t.C:
100121 case <-ctx.Done():
122+ t.Stop()
101123 return ctx.Err()
102124 }
103125 }
@@ -46,9 +46,20 @@ func tcpProbe(ctx context.Context, addr string, timeout time.Duration) error {
46 log.Debug().Err(err).Str("addr", addr).Int("attempt", attempts).Msg("TCP probe attempt failed")46 log.Debug().Err(err).Str("addr", addr).Int("attempt", attempts).Msg("TCP probe attempt failed")
47 }47 }
48 48
49+ sleepInterval := 500 * time.Millisecond
50+ if deadline, ok := ctx.Deadline(); ok {
51+ if rem := time.Until(deadline); rem < sleepInterval {
52+ sleepInterval = rem
53+ }
54+ }
55+ if sleepInterval <= 0 {
56+ return ctx.Err()
57+ }
58+ t := time.NewTimer(sleepInterval)
49 select {59 select {
50- case <-time.After(500 * time.Millisecond):60+ case <-t.C:
51 case <-ctx.Done():61 case <-ctx.Done():
62+ t.Stop()
52 return ctx.Err()63 return ctx.Err()
53 }64 }
54 }65 }
@@ -95,9 +106,20 @@ func httpProbe(ctx context.Context, url string, timeout time.Duration) error {
95 }106 }
96 }107 }
97 108
109+ sleepInterval := time.Second
110+ if deadline, ok := ctx.Deadline(); ok {
111+ if rem := time.Until(deadline); rem < sleepInterval {
112+ sleepInterval = rem
113+ }
114+ }
115+ if sleepInterval <= 0 {
116+ return ctx.Err()
117+ }
118+ t := time.NewTimer(sleepInterval)
98 select {119 select {
99- case <-time.After(time.Second):120+ case <-t.C:
100 case <-ctx.Done():121 case <-ctx.Done():
122+ t.Stop()
101 return ctx.Err()123 return ctx.Err()
102 }124 }
103 }125 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close