Skip to content

fix(datastore): synchronize in-memory routing datastore - #1890

Merged
tkircsi merged 1 commit into
agntcy:mainfrom
Baltsat:fix/1886-mapdatastore-concurrency-dco
Jul 27, 2026
Merged

tkircsi merged 1 commit into
agntcy:mainfrom
Baltsat:fix/1886-mapdatastore-concurrency-dco

Conversation

@Baltsat

@Baltsat Baltsat commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • wrap the default in-memory MapDatastore with sync.MutexWrap
  • add a concurrent Query/Put regression test at the datastore construction boundary
  • leave the persistent Badger backend unchanged

Root cause

The default datastore constructor returned a raw github.com/ipfs/go-datastore.MapDatastore. That implementation is not thread-safe. Directory shares this datastore across routing components that can query and write concurrently, matching the reported concurrent map iteration and map write panic in MapDatastore.Query.

Synchronizing at construction covers every consumer of the shared in-memory datastore; locking only the failing query path would leave other direct readers and writers uncoordinated.

Fixes #1886

Validation

  • pre-fix focused race reproduction: fails with a Go race report and fatal error: concurrent map iteration and map write
  • synchronized focused reproduction: go test -race -count=10 ./safe passes
  • gofmt passes for both changed files
  • whitespace/diff validation passes
  • the replacement commit author, committer, and DCO sign-off use the same verified email

The repository-native test could not be executed in the worker VM because it had Go 1.23.2 while server/go.mod requires Go 1.26.5, and the environment could not fetch that toolchain/module graph. The new test is included so upstream CI can compile and exercise the production construction path.

@Baltsat
Baltsat requested a review from a team as a code owner July 25, 2026 06:25
Copilot AI review requested due to automatic review settings July 25, 2026 06:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions
github-actions Bot force-pushed the fix/1886-mapdatastore-concurrency-dco branch from 8349f90 to 644330d Compare July 25, 2026 12:17
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for tracking this down and fixing it, @Baltsat! 🎉

@tkircsi
tkircsi merged commit 3a3a1b4 into agntcy:main Jul 27, 2026
50 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 50-199 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Routing crashes during notification handling

3 participants