Skip to content

fix race condition leading to seg faults#741

Closed
anshalshukla wants to merge 2 commits into
mainfrom
fix-seg-faults
Closed

fix race condition leading to seg faults#741
anshalshukla wants to merge 2 commits into
mainfrom
fix-seg-faults

Conversation

@anshalshukla
Copy link
Copy Markdown
Collaborator

@anshalshukla anshalshukla commented Apr 16, 2026

The fetched_blocks map in the network layer is accessed by both the main thread and the libp2p thread. The main thread was using a shallow copy of the blocks, which caused segmentation faults during long chain syncs. This happened because blocks could be pruned after finalization while still being referenced by the main thread.

This issue doesn’t appear when the chain remains fully synced, since pruning and access don’t overlap in the same way.

The issue happens because the hashmap resizes when new blocks are inserted on the network thread. This causes rehashing, which moves keys to different positions. Meanwhile, the main thread still relies on the old positions based on the previous size, so those references become invalid and lead to a panic.

To fix this, don’t share internal hashmap positions across threads. Either lock the hashmap while it’s being accessed or pass a full copy of the data instead of references.

@anshalshukla
Copy link
Copy Markdown
Collaborator Author

Closing this as the other approach suggested by @ch4r10t33r seems better

@GrapeBaBa
Copy link
Copy Markdown
Member

GrapeBaBa commented Apr 20, 2026

What is the blocking issue right now for schedule network callback in the main eventloop(#326) right now? a lot of mutex added recently which could cause live/dead lock issue or perf regression, it should be easy to avoid race by reducing the logic in the network thread. @anshalshukla @ch4r10t33r @g11tech

@anshalshukla
Copy link
Copy Markdown
Collaborator Author

Included in #765

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