Skip to content

Add thread-safety support (connection pooling) #15

@CaptainDriftwood

Description

@CaptainDriftwood

Description

IcapClient is not thread-safe. Multiple threads sharing a client instance could corrupt socket state.

Current Issues

  • Socket interleaving if two threads call methods concurrently
  • Check-then-act races in connection logic
  • State corruption during disconnect

Implementation Options

  1. Lock-based (threading.RLock) - Simple, serializes operations
  2. Thread-local storage - Each thread gets own client
  3. Connection pool (IcapClientPool) - Bounded resources, efficient reuse
  4. Stateless - New socket per operation

Recommendation

Implement Option 1 (lock-based) as default for basic thread-safety, and provide Option 3 (connection pool) as IcapClientPool for high-throughput use cases.

Python Compatibility

All approaches work across Python 3.8-3.14. Note: Python 3.13+ free-threaded mode (PEP 703) makes explicit locking more critical.

Priority

Future enhancement - Not blocking release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions