Skip to content

Add mutex to defergroup.Group for thread safety#2

Draft
KSH-KOR wants to merge 1 commit intojaeyeom:masterfrom
KSH-KOR:defergroup-mutex
Draft

Add mutex to defergroup.Group for thread safety#2
KSH-KOR wants to merge 1 commit intojaeyeom:masterfrom
KSH-KOR:defergroup-mutex

Conversation

@KSH-KOR
Copy link
Copy Markdown

@KSH-KOR KSH-KOR commented Apr 1, 2026

Changelog

  • Add sync.Mutex to defergroup.Group struct
  • Protect Defer, Done, CancelAll, and Transfer methods with mutex for concurrent safety
  • Done snapshots and clears the function list under the lock, then executes callbacks unlocked
  • Add TestDeferConcurrent covering 100 concurrent goroutines calling Defer

Testing

  • go test -race ./defergroup/... — passes with no race conditions detected
  • bazel test //defergroup:go_default_test — passes

Version Compatibility

  • No API changes; fully backward compatible

Demo

  • N/A (internal concurrency safety, no UI or feature flag)

Ops Impact

  • None

Protect Defer, Done, CancelAll, and Transfer with sync.Mutex so Group
can be used safely from multiple goroutines. Done snapshots and clears
the function list under the lock, then runs callbacks unlocked.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@KSH-KOR
Copy link
Copy Markdown
Author

KSH-KOR commented Apr 2, 2026

@jaeyeom Cloud you review this PR?

@KSH-KOR KSH-KOR marked this pull request as draft April 2, 2026 07:20
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