Repository navigation
hub: fix race that drops sources subscribing at the same time - #97
Merged
maoueh merged 2 commits intoNov 23, 2026
Merged
Conversation
ForkableHub.subscribe appended to the list of subscribers from the CallWithBlocks* callbacks, which only hold the forkable's read lock. Sources created at the same time could overwrite each other's entry. A lost one was sent the blocks the hub already had and then never a live block, with no error, so its stream stayed open and silent. The list now has its own mutex. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKy2EkG5bfA6HNM1MZSHWz
Also drop the copy on append: appending past a snapshot's length does not change what the snapshot holds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKy2EkG5bfA6HNM1MZSHWz
YaroShkvorets
marked this pull request as ready for review
November 19, 2026 17:33
maoueh
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We've run into this issue where a consumer of a relayer stops receiving blocks after reconnecting, with no error on either side. The relayer is healthy and keeps serving its other clients; the affected one stays connected and silent until it is restarted.
What happens
ForkableHub.subscribeappends toh.subscribersfrom theCallWithBlocks*callbacks. Those hold the forkable's read lock, so sources created at the same time runsubscribeconcurrently and can overwrite each other's entry.A source that loses its entry:
broadcastBlockdoesn't know it,How we saw it
One of two relayers went down. Its eight clients (tier1 and firehose) sent their block requests to the other relayer within 8 ms. Six carried on. Two received the initial blocks and then nothing, for hours, until they were restarted.
The same path serves every stream that joins a hub (
SourceFromBlockNum,SourceFromCursor,SourceThroughCursor), so two requests arriving together on a firehose or tier1 can lose one the same way. We have not looked for that case in production.Change
subscribersgets its own mutex, taken bysubscribe,unsubscribe,broadcastBlockand the hub's shutdown.subscribestill runs under the forkable's read lock, so no live block is broadcast between reading the initial blocks and registering the subscription.Tested
TestForkableHub_ConcurrentSubscribe: 8 sources created at once, 200 rounds, each must receive the next live block. Without the fix it failed 10 runs out of 10, with the hub holding 4 to 7 subscribers instead of 8. With the fix it passes, also under-race.go test ./...passes.🤖 Made with Claude Code ·
4c9654be-9023-454a-a3e6-4d57d0aa37f8