Skip to content

Arm peer message writer wakeup before refilling its buffer - #1069

Open
softganz88 wants to merge 1 commit into
anacrolix:masterfrom
softganz88:agent/peer-writer-wakeup
Open

Arm peer message writer wakeup before refilling its buffer#1069
softganz88 wants to merge 1 commit into
anacrolix:masterfrom
softganz88:agent/peer-writer-wakeup

Conversation

@softganz88

Copy link
Copy Markdown

What changed

  • arm writeCond before fillWriteBuffer evaluates whether more peer messages are available
  • add a deterministic regression that forces a broadcast during the first empty refill and requires a second refill

Why

BroadcastCond does not retain a broadcast when no Signaled channel is armed. The peer message writer previously called fillWriteBuffer before arming writeCond, while the refill observes peer state outside cn.mu. A state transition could therefore broadcast during refill, leave the write buffer empty, and be lost before the writer began waiting. With no later transition, the writer remained asleep.

Arming the condition first retains a broadcast from that refill window without changing the existing closed-channel or keepalive selection.

Validation

  • go test -run '^TestPeerConnMsgWriterArmsWakeupBeforeRefill$' -count=100 .
  • cargo build in the pinned storage/possum/lib submodule, then go test ./...
  • gofmt and git diff --check

The regression uses channel synchronization and contains no timing sleep for the target interleaving. It fails on commit 8c67afb7185d42ea94dcced246596d79d35feb64 and passes after this change.

@softganz88
softganz88 marked this pull request as ready for review July 28, 2026 15:50
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