Read the drop counter atomically and set the WHOIS fetcher before serving (closes #115) #139

Merged
clawbot merged 1 commits from issue-115-data-races into next 2026-10-20 03:18:01 +02:00
Collaborator

Implements #115.

The read loop added to a handler's drop count with atomic.AddUint64 while GetHandlerStats (behind /api/v1/stats) and the ten-second metrics log read it as a plain field. The count is now an atomic.Uint64 read with Load, like the total beside it.

Run gave the HTTP server its WHOIS fetcher after the server had started, while request handlers read it without a lock. The fetcher is now created, started and set before server.Start, and the SetASNFetcher doc comment says to call it first.

What the diff does not show:

  • The new test has no assertion that fails before the fix; it fails through the race detector, which reports the add in the read loop against the read in GetHandlerStats.
  • It polls GetHandlerStats in a loop with no sleep instead of waiting for a signal from the read loop: such a signal would order the drops before the reads and hide the race.
  • If the server cannot listen, the fetcher is now already running; Shutdown stops it, as it stops the streamer, which already started before the server.

Disclosures:

  • Unverified: the fetcher change has no test, since none can make a request arrive between the server starting and the fetcher being set.
  • internal/server/server.go changes only in that doc comment.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/routewatch/issues/115. The read loop added to a handler's drop count with `atomic.AddUint64` while `GetHandlerStats` (behind `/api/v1/stats`) and the ten-second metrics log read it as a plain field. The count is now an `atomic.Uint64` read with `Load`, like the total beside it. `Run` gave the HTTP server its WHOIS fetcher after the server had started, while request handlers read it without a lock. The fetcher is now created, started and set before `server.Start`, and the `SetASNFetcher` doc comment says to call it first. What the diff does not show: - The new test has no assertion that fails before the fix; it fails through the race detector, which reports the add in the read loop against the read in `GetHandlerStats`. - It polls `GetHandlerStats` in a loop with no sleep instead of waiting for a signal from the read loop: such a signal would order the drops before the reads and hide the race. - If the server cannot listen, the fetcher is now already running; `Shutdown` stops it, as it stops the streamer, which already started before the server. Disclosures: - Unverified: the fetcher change has no test, since none can make a request arrive between the server starting and the fetcher being set. - `internal/server/server.go` changes only in that doc comment. Model: opus-5-5
clawbot added the needs-review label 2026-10-20 03:11:21 +02:00
clawbot self-assigned this 2026-10-20 03:11:21 +02:00
clawbot added 1 commit 2026-10-20 03:11:21 +02:00
The read loop added to a handler's drop count atomically while the
statistics endpoint and the metrics log read it as a plain field, a data
race whenever messages were dropped. The count is now an atomic.Uint64,
read with Load. A test reads the handler statistics while the read loop
drops messages for a handler that never finishes one.

Run created the WHOIS fetcher and gave it to the HTTP server after the
server had started, while request handlers could read it. The fetcher is
now set before the server starts.

Model: opus-5-5
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 2f238236bd into next 2026-10-20 03:18:01 +02:00
clawbot deleted branch issue-115-data-races 2026-10-20 03:18:01 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/routewatch#139