Skip to content

fix: add mutex to Owner for goroutine-safe linked list operations #1

Merged
AnatoleLucet merged 1 commit intoloom-go:mainfrom
gfanton:fix/owner-goroutine-safety
Mar 27, 2026
Merged

fix: add mutex to Owner for goroutine-safe linked list operations #1
AnatoleLucet merged 1 commit intoloom-go:mainfrom
gfanton:fix/owner-goroutine-safety

Conversation

@gfanton
Copy link
Copy Markdown
Contributor

@gfanton gfanton commented Mar 27, 2026

Fix data race in Owner linked list when signals are written from a different goroutine than the one that created the reactive graph.

Root: AddChild, DisposeChildren, OnCleanup, OnError, and context map access had no synchronization. When Signal.Write from goroutine B triggers recompute of a node created on goroutine A, new children are added to A's owner tree concurrently — corrupting the doubly-linked list (infinite loop → freeze).

Fix: Add sync.Mutex to Owner with snapshot-then-release pattern — lock to snapshot/detach, unlock before executing callbacks or disposing children. No deadlocks: parent lock is always released before acquiring child locks.

See owner_race_test.go, 4 tests covering AddChild vs DisposeChildren, OnCleanup vs Cleanup, concurrent context access, and OnError vs recover. All fail with -race before the fix.

@AnatoleLucet AnatoleLucet force-pushed the fix/owner-goroutine-safety branch from 5f33e68 to dd62b97 Compare March 27, 2026 15:25
@AnatoleLucet AnatoleLucet force-pushed the fix/owner-goroutine-safety branch from dd62b97 to 71cf04f Compare March 27, 2026 16:18
@AnatoleLucet AnatoleLucet merged commit b5f1542 into loom-go:main Mar 27, 2026
12 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.

2 participants