Skip to content

M15/M16: connection pool returned nil clients when saturated and panicked on shutdown #174

Closed

Description

@scttfrdmn

Audit defects M15 and M16, reproduced independently by the endpoint test above, plus two further defects the regression tests surfaced.

1. A saturated pool returned nil forever

Get returned *s3.Client alone, and nil once currentSize == maxSize. The select carried a default arm, so it never reached its own time.After case — the timeout was dead code and a full pool failed instantly rather than waiting for the connection about to come back.

draw 0: client=true currentSize=1 idle=0
draw 1: client=true currentSize=2 idle=0
draw 2: client=true currentSize=3 idle=0
draw 3: client=false currentSize=3 idle=0
draw 4: client=false currentSize=3 idle=0
--- after returning one ---
draw after Put: client=true

All six call sites dereferenced the result unchecked, including executeWithAccelerationFallback — the path every GET and PUT takes. On the default 8-connection pool the ninth concurrent operation panicked and unmounted the filesystem under every open descriptor.

2. Close raced Put into a send on a closed channel

Put checked closed under the read lock, released it, then sent. Close took the write lock, set closed, then closed the channel. The losing interleaving is a send on a closed channel — a panic during unmount, on the path every deferred Put takes.

3. The pool overshot maxSize under concurrency

canCreateConnection and createConnection took the lock separately, so N concurrent callers all passed the capacity check before any incremented. Surfaced by a regression test: 16 concurrent workers against a pool of 4 ran the factory 16 times and discarded 12 clients on return.

4. Resize could deadlock the pool

Resize raised maxSize without touching the idle channel, whose buffer is fixed at construction. A capacity reservation for a slot with no buffer space makes the return block while holding the write lock.

Fix

  • Get/GetWithTimeout return (*s3.Client, error) and block up to the timeout; the timeout error names the in-use count and storage.s3.pool_size
  • Put does its closed check and send in one critical section; Close drains rather than closes, and wakes blocked waiters via a done channel so shutdown does not make them wait out the full timeout
  • reserving a slot is one atomic operation, and a factory failure releases the reservation
  • Resize refuses to grow past the constructed capacity and says to raise storage.s3.pool_size instead; shrinking converges by dropping checked-out connections as they return
  • Warmup respects maxSize, joins factory errors, honours context cancellation, and refuses a closed pool

pool_test.go covers exhaustion-waits-then-wakes, the timeout message, concurrent Put/Close across 50 rounds under -race, concurrent draw/return bounded by maxSize, and the Resize/Warmup edges.

Activity

  1. added
    type: bug
    priority: critical
    area: s3
    on Jul 31, 2026
  2. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed in v0.10.1 (ae0423b). GetWithTimeout returns (*s3.Client, error) instead of a bare pointer that was nil once the pool saturated and was dereferenced unchecked at six call sites, including the one every GET and PUT reaches. Close no longer closes a channel with unsynchronized producers still sending.

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

    area: s3priority: criticaltype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions