Commit 3a1a6db
fix: prevent pool _size from going negative on concurrent close
pool.close() previously set _size = 0 unconditionally and force-closed
in-use connections. When in-flight acquire() coroutines later hit their
cleanup paths, they decremented _size below zero, permanently corrupting
the pool's size accounting.
Change close() to only close idle connections (decrementing _size per
connection) and leave in-use connections to be cleaned up by acquire()'s
context manager, which already checks _closed and closes instead of
returning to the pool. This eliminates the race between close() and
acquire()'s cleanup paths.
Also resolves #088 (connections added during close being leaked by
_in_use.clear()) since close() no longer touches _in_use at all.
Closes #080
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 4c3d08d commit 3a1a6db
2 files changed
+59
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
164 | 163 | | |
165 | 164 | | |
166 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
188 | 227 | | |
189 | 228 | | |
190 | 229 | | |
| |||
255 | 294 | | |
256 | 295 | | |
257 | 296 | | |
258 | | - | |
259 | | - | |
| 297 | + | |
| 298 | + | |
260 | 299 | | |
261 | 300 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
275 | 305 | | |
276 | | - | |
277 | | - | |
278 | | - | |
| 306 | + | |
| 307 | + | |
279 | 308 | | |
280 | | - | |
281 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
282 | 312 | | |
283 | | - | |
284 | | - | |
| 313 | + | |
| 314 | + | |
285 | 315 | | |
286 | 316 | | |
287 | 317 | | |
| |||
0 commit comments