Skip to content

Potential Infinite Spin Livelock in STMVariable Write Operations #17

Open

Description

@engineering87

Potential Infinite Spin Livelock in STMVariable Write Operations

Priority

Medium - Edge Case

Component

Core/STMVariable.cs - Write method (lines 61-101)

Description

The direct write operation on STMVariable uses an unbounded spin loop to acquire the write reservation. In edge case scenarios where a reservation is held indefinitely (e.g., thread abort, unhandled exception, or system deadlock), this could result in a livelock condition where the spinning thread never exits.

Impact

  • Likelihood: Low - requires exceptional failure conditions
  • Severity: High if triggered - thread becomes unresponsive
  • Affected scenarios: High-contention writes or abnormal thread termination

Reproduction Conditions

This is a theoretical edge case that would require:

  1. A writer thread acquiring a reservation (odd version)
  2. That thread terminating abnormally before releasing
  3. Another thread attempting to write to the same variable

Suggested Mitigation

Consider adding one of the following safeguards:

  • Maximum spin count with timeout exception
  • Configurable spin limit with fallback behavior
  • Detection mechanism for stuck reservations with automatic recovery

Verification Needed

Requires stress testing and fault injection to confirm if this edge case is realistic in production scenarios.

Activity

  1. added
    bug
    on Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions