You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recycling objects with a sync.Pool risks amplifying the impact of bugs.
If the object is not reset to be functionally indistinguishable from a
newly-constructed one before being returned to the pool, the unlucky
recipient of the recycled object could misbehave through no fault of its
own. And what's worse, such bugs would likely manifest as Heisenbugs as
they would only happen when objects returned to the pool are being
reused, i.e. a program with lots of concurrency and lots of lock churn.
Make the pool optimization functionally transparent so the impact of
counter bugs does not extend beyond the scope it would have had without
the pool optimization. Defensively reset the lock counters before
returning them to the pool and after taking them from the pool. And add
testing-only code which asserts that the invariants are upheld to ensure
that the defensive coding is not papering over real bugs.
Signed-off-by: Cory Snider <[email protected]>
0 commit comments