Skip to content

Synchronise the endpoint stats between the capture and stats threads - #35

Merged
git-hulk merged 1 commit into
masterfrom
design-stats-locking
Sep 2, 2026
Merged

Synchronise the endpoint stats between the capture and stats threads#35
git-hulk merged 1 commit into
masterfrom
design-stats-locking

Conversation

@git-hulk

@git-hulk git-hulk commented Sep 2, 2026

Copy link
Copy Markdown
Owner

The stats thread walked syn_tab and read every query_stats in it while
the capture thread was inserting endpoints and bumping counters, with
nothing between them. Replaying a 16000 packet capture while polling
the stats endpoint reports six data races under ThreadSanitizer and
aborts: in stats_incr, in create_stats_object and on srv->stopped.

  • Add stats_lock to the sniffer, held by the capture thread around
    every syn_tab lookup, insert and counter update, and by the stats
    thread across the whole walk so a response cannot be counted half
    way through serialisation. The requests table stays lock free: only
    the capture thread touches it.

  • srv->stopped is written by server_terminate, which also runs from
    the signal handler, and read by the stats thread's loop. It is now
    sig_atomic_t accessed through the compiler's atomic builtins.

  • Skip the endpoint instead of dereferencing NULL when the calloc for
    a new query_stats fails.

make test-race rebuilds under ThreadSanitizer and replays a generated
stress capture while polling the endpoint; it reports 0 races where the
previous code reported 6. It is opt-in because it clobbers the ordinary
build, and runs as its own CI job.

🤖 Generated with Claude Code

@git-hulk
git-hulk force-pushed the design-stats-locking branch from 22dedae to a66029e Compare September 2, 2026 11:45
@git-hulk
git-hulk force-pushed the design-stats-locking branch from a66029e to 79b88cf Compare September 2, 2026 11:46
@git-hulk
git-hulk force-pushed the design-stats-locking branch 2 times, most recently from 9ecb72f to e1dfaf1 Compare September 2, 2026 11:58
@git-hulk
git-hulk force-pushed the design-stats-locking branch from e1dfaf1 to b5aa730 Compare September 2, 2026 12:15
@git-hulk
git-hulk force-pushed the design-stats-locking branch from b5aa730 to 5feda23 Compare September 2, 2026 12:24
@git-hulk
git-hulk force-pushed the design-stats-locking branch from 5feda23 to aeb43a8 Compare September 2, 2026 12:26
Base automatically changed from license-mit-headers to master September 2, 2026 12:27
The stats thread walked syn_tab and read every query_stats in it while
the capture thread was inserting endpoints and bumping counters, with
nothing between them. Replaying a 16000 packet capture while polling
the stats endpoint reports six data races under ThreadSanitizer and
aborts: in stats_incr, in create_stats_object and on srv->stopped.

  - Add stats_lock to the sniffer, held by the capture thread around
    every syn_tab lookup, insert and counter update, and by the stats
    thread across the whole walk so a response cannot be counted half
    way through serialisation. The requests table stays lock free: only
    the capture thread touches it.

  - srv->stopped is written by server_terminate, which also runs from
    the signal handler, and read by the stats thread's loop. It is now
    sig_atomic_t accessed through the compiler's atomic builtins.

  - Skip the endpoint instead of dereferencing NULL when the calloc for
    a new query_stats fails.

`make test-race` rebuilds under ThreadSanitizer and replays a generated
stress capture while polling the endpoint; it reports 0 races where the
previous code reported 6. It is opt-in because it clobbers the ordinary
build, and runs as its own CI job.

Assistant By Opus 5

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@git-hulk
git-hulk force-pushed the design-stats-locking branch from aeb43a8 to d2d7b60 Compare September 2, 2026 12:27
@git-hulk
git-hulk merged commit 2c1c3ef into master Sep 2, 2026
6 checks passed
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.

1 participant