Skip to content

CRITICAL: Synchronized block holds lock during network I/O (5-90+ seconds) #69

@sfloess

Description

@sfloess

Problem

The synchronization fix for the TOCTOU race condition (commit 705609f) holds the monitor lock during potentially long network operations, serializing all API calls and blocking other operations.

Evidence

ClaudeClient.java lines 194-199:

synchronized (this) {
    if (closed) {
        throw new ClaudeException("Client has been closed");
    }
    return retryPolicy.executeWithRetry(() -> sendMessageInternal(userMessage));
}

The lock is held while:

  • Network I/O happens (5+ seconds per API call)
  • Retry logic executes with exponential backoff (up to 30s per retry)
  • Thread.sleep() during backoff (up to 3 retries)

Total lock time: Potentially 90+ seconds in worst case (3 retries × 30s each)

Impact

Thread A calls sendMessage(), acquires lock, makes network call (5s) → Thread B calls clearHistory(), blocks waiting for lock → Thread C calls close(), blocks waiting for lock → All operations serialized, no concurrent API calls possible, poor throughput under load

Recommendation

Use fine-grained locking or redesign with proper state machine and lifecycle management.

Location


Detected by AI-assisted code review on 2026-06-05 (iteration 3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-modulesAffects AI modulesbugSomething isn't workingcriticalCritical priority - must fix immediately

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions