Skip to content

fix: thread-unsafe global state in id.c - #131

Merged
flyingrobots merged 1 commit into
mainfrom
fix/thread-unsafe-siphash-key
Jun 24, 2025
Merged

flyingrobots merged 1 commit into
mainfrom
fix/thread-unsafe-siphash-key

Conversation

@flyingrobots

Copy link
Copy Markdown
Owner

Summary

Changes

  • Replace g_siphash_key_initialized flag with pthread_once_t
  • Use pthread_once() to guarantee single initialization
  • Add pthread to LDFLAGS in Makefile
  • Free error on fallback path to prevent memory leak

Test Plan

  • All existing tests pass
  • Thread safety test (test_id_thread_safety) verifies concurrent access
  • No new compiler warnings
  • Pre-commit hooks pass

🤖 Generated with Claude Code

Replace race-prone boolean flag with pthread_once for SipHash key initialization.
This ensures the key is initialized exactly once even with concurrent access.

- Replace g_siphash_key_initialized flag with pthread_once_t
- Use pthread_once() to guarantee single initialization
- Add pthread to LDFLAGS in Makefile
- Free error on fallback path to prevent memory leak

Fixes TODO #1 from TASKLIST.md

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@flyingrobots
flyingrobots merged commit 3b66d7f into main Jun 24, 2025
@flyingrobots
flyingrobots deleted the fix/thread-unsafe-siphash-key branch June 24, 2025 16:07
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