Commit 0d9b8b8
committed
fix: rollback on drop so write conn returns to pool clean (#46)
Dropping an ActiveInterruptibleTransaction without commit/rollback left
the write connection in the pool with an open transaction. sqlx pools
reuse connections rather than closing them, so SQLite's close-time
auto-rollback never fired, and the next acquire_writer() got a
connection where BEGIN IMMEDIATE failed with "cannot start a
transaction within a transaction".
Drop now takes the writer and spawns a tokio task that issues ROLLBACK
(and detach_if_attached) before the connection is released to the pool.
The insert()/remove()/abort_all() paths that previously relied on Drop
now roll back explicitly.
As defense-in-depth against any other writer path that might leak a
transaction (e.g. user code that does BEGIN and returns early), the
write pool gets an after_release hook that unconditionally runs
ROLLBACK, ignoring the benign "no transaction is active" error.
Adds a regression test that mirrors the reporter's MCVE: start an
interruptible transaction, drop it, start a second one, and assert the
second succeeds and only its data commits.
Updates the README to document the auto-rollback-on-drop guarantee
(including early returns via ?).1 parent 240eb77 commit 0d9b8b8
4 files changed
Lines changed: 170 additions & 47 deletions
File tree
- crates
- sqlx-sqlite-conn-mgr/src
- sqlx-sqlite-toolkit
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
385 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
386 | 388 | | |
387 | 389 | | |
388 | 390 | | |
| |||
784 | 786 | | |
785 | 787 | | |
786 | 788 | | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
787 | 793 | | |
788 | 794 | | |
789 | 795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
180 | 188 | | |
181 | 189 | | |
182 | 190 | | |
183 | 191 | | |
184 | 192 | | |
185 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
186 | 200 | | |
187 | 201 | | |
188 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
243 | 276 | | |
244 | 277 | | |
245 | 278 | | |
| |||
288 | 321 | | |
289 | 322 | | |
290 | 323 | | |
291 | | - | |
292 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
293 | 328 | | |
294 | 329 | | |
295 | 330 | | |
296 | 331 | | |
297 | 332 | | |
298 | 333 | | |
299 | 334 | | |
300 | | - | |
301 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
302 | 339 | | |
303 | 340 | | |
304 | 341 | | |
| |||
308 | 345 | | |
309 | 346 | | |
310 | 347 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
315 | 357 | | |
316 | | - | |
| 358 | + | |
317 | 359 | | |
318 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
319 | 364 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | 365 | | |
325 | 366 | | |
326 | 367 | | |
327 | 368 | | |
328 | 369 | | |
329 | | - | |
330 | | - | |
| 370 | + | |
| 371 | + | |
331 | 372 | | |
332 | 373 | | |
333 | 374 | | |
334 | 375 | | |
335 | 376 | | |
336 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
337 | 381 | | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
342 | 385 | | |
343 | | - | |
344 | | - | |
345 | | - | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
346 | 389 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
359 | 403 | | |
360 | | - | |
361 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
362 | 410 | | |
363 | 411 | | |
364 | 412 | | |
| |||
Lines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
0 commit comments