Skip to content

fix: tests: buffer the logSource channel#203

Merged
rowansmithau merged 1 commit into
mainfrom
rowan/logger_test_fix
Jun 22, 2026
Merged

fix: tests: buffer the logSource channel#203
rowansmithau merged 1 commit into
mainfrom
rowan/logger_test_fix

Conversation

@rowansmithau

Copy link
Copy Markdown
Member

Bug: fakeAgentAPI.PostLogSource sends on an unbuffered logSource channel, which blocks the HTTP handler goroutine if a second PostLogSource call arrives after the test has stopped reading (e.g. from a Kubernetes-spawned pod retrying after a context canceled), causing httptest.Server.Close() to deadlock waiting for the handler to finish.

Fix: Buffer the logSource and logs channels with a capacity of 32, allowing the fake server to absorb all incoming calls without blocking regardless of whether the test is actively reading.

example failure: https://github.com/coder/coder-logstream-kube/actions/runs/27814097460/job/82310947374?pr=201#step:5:472

prior to making changes when testing with:

pass=0; fail=0
for i in $(seq 1 100); do
  if GOTOOLCHAIN=auto go test -count=1 -v -tags=integration \
  -run 'TestIntegration_ReplicaSetEvents|Test_logQueuer/RetryMechanism' \
  -timeout 30s ./... > /tmp/run-$i.log 2>&1; then
    ((pass++)); rm /tmp/run-$i.log
  else
    ((fail++))
  fi
  printf "Run %3d/100 — pass: %d  fail: %d\n" $i $pass $fail
done
printf "\nFinal: %d passed, %d failed out of 100\n" $pass $fail

it would produce a failure rate of 4/100.

post change testing again resulted in 0 failures.

created in Mux with the help of Claude

@rowansmithau rowansmithau self-assigned this Jun 22, 2026
@rowansmithau rowansmithau marked this pull request as ready for review June 22, 2026 00:31
@rowansmithau rowansmithau merged commit 278e918 into main Jun 22, 2026
4 checks passed
@rowansmithau rowansmithau deleted the rowan/logger_test_fix branch June 22, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants