Skip to content

#583 Make Trace array thread-safe with Mutex#605

Merged
yegor256 merged 2 commits into
zerocracy:masterfrom
VasilevNStas:583-trace-thread-safe
Jul 17, 2026
Merged

#583 Make Trace array thread-safe with Mutex#605
yegor256 merged 2 commits into
zerocracy:masterfrom
VasilevNStas:583-trace-thread-safe

Conversation

@VasilevNStas

@VasilevNStas VasilevNStas commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Problem

The @trace array in Fbe::Middleware::Trace is accessed from multiple threads without synchronization. When Octokit fires concurrent requests, a race condition occurs: simultaneous read/write on @trace can corrupt the data.

Solution

  1. Trace middleware (lib/fbe/middleware/trace.rb):

    • Added @mutex = Mutex.new in constructor
    • All @trace reads/writes wrapped with @mutex.synchronize
  2. Decoor (lib/fbe/middleware/trace.rb):

    • Added trace_mutex parameter to print_trace!
    • @trace.clear wrapped with @mutex.synchronize
  3. Octo (lib/fbe/octo.rb):

    • Created trace_mutex = Mutex.new
    • Passed to Trace middleware constructor and print_trace! call
  4. Rubocop (.rubocop.yml):

    • Added trace_mutex to Elegant/GoodVariableName AllowedNames

Tests

90 tests, 0 failures, 0 errors, 2 skips

Closes #583

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@yegor256 please review

Comment thread .rubocop.yml Outdated
- workflow_run_usage
Elegant/GoodVariableName:
AllowedNames:
- trace_mutex

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@VasilevNStas VasilevNStas left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yegor256

Renamed trace_mutex to mutex as suggested. Thanks for the reference
plz review

@yegor256
yegor256 merged commit 143705b into zerocracy:master Jul 17, 2026
10 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.

Trace array is not thread-safe — concurrent append and clear corrupt entries

2 participants