Commit a43f44c
FIX: Release GIL around remaining blocking ODBC paths (#565)
Audit follow-up to the previous teardown fix. Identified and addressed
four additional ODBC call sites that performed blocking network
round-trips while holding the GIL - each one another potential
in-process-forwarder deadlock waiting to be reported.
Fixed call sites:
* Connection::isAlive() -> SQLGetConnectAttr(SQL_ATTR_CONNECTION_DEAD)
The MS ODBC driver implements this as a TCP-level probe. Hit by
every connection-pool checkout, making it one of the
highest-frequency GIL-held network calls in the driver. The
existing comment in connection_pool.cpp:50 already claimed
isAlive() released the GIL - it didn't until this change.
* Connection::getInfo() -> SQLGetInfo (both probe and data call)
Several info types (SQL_DATABASE_NAME, SQL_DBMS_NAME/VER,
SQL_USER_NAME, SQL_SERVER_NAME, ...) trigger a server query.
* BindParameters() -> SQLDescribeParam
Issued by the driver as sp_describe_undeclared_parameters when a
parameter has SQL_UNKNOWN_TYPE - hit on every parametrized query
that includes a None value.
* Connection::getAutocommit() -> SQLGetConnectAttr(SQL_ATTR_AUTOCOMMIT)
Client-cached in practice, wrapped for consistency with the other
connection-attribute paths.
All four are reached only from Python-callable wrappers with the GIL
held, so a plain py::gil_scoped_release is sufficient (no
is_python_finalizing guard needed - those are only required for the
destructor cascade fixed in the prior commit).
Adds test_introspection_paths_through_python_tcp_forwarder_do_not_deadlock
which exercises getinfo(SQL_DBMS_NAME), a parametrized SELECT with a
None parameter (forces SQLDescribeParam), and the autocommit getter,
all through the in-process Python TCP forwarder under a 30s watchdog.
Verified: test hangs (watchdog fires at 30s) without the C++ changes
and passes (<1s) with them. Full pytest suite: 1767 passed, 0 failed.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 9a3b84c commit a43f44c
3 files changed
Lines changed: 135 additions & 10 deletions
File tree
- mssql_python/pybind
- connection
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
251 | 258 | | |
252 | 259 | | |
253 | 260 | | |
| |||
452 | 459 | | |
453 | 460 | | |
454 | 461 | | |
455 | | - | |
456 | | - | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
457 | 473 | | |
458 | 474 | | |
459 | 475 | | |
| |||
582 | 598 | | |
583 | 599 | | |
584 | 600 | | |
585 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
586 | 606 | | |
587 | | - | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
588 | 612 | | |
589 | 613 | | |
590 | 614 | | |
| |||
615 | 639 | | |
616 | 640 | | |
617 | 641 | | |
618 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
619 | 648 | | |
620 | 649 | | |
621 | 650 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
638 | | - | |
639 | | - | |
640 | | - | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
641 | 649 | | |
642 | 650 | | |
643 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 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 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
233 | 292 | | |
234 | 293 | | |
235 | 294 | | |
| |||
326 | 385 | | |
327 | 386 | | |
328 | 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 | + | |
329 | 415 | | |
330 | 416 | | |
331 | 417 | | |
332 | 418 | | |
333 | 419 | | |
334 | 420 | | |
335 | 421 | | |
| 422 | + | |
| 423 | + | |
336 | 424 | | |
0 commit comments