fix: MSSQL connection left in busy state after insert#2169
fix: MSSQL connection left in busy state after insert#2169seladb wants to merge 6 commits intotortoise:developfrom
Conversation
|
@abondar I think this should fix the issue that causes MSSQL CI to fail |
|
Did you check that issueing "SET NOCOUNT ON" before execute many doesn't work? Is it limited only to individual inserts? |
Yes, this was one of my attempts that didn't work: 339cebe According to Claude:
Yes, you're right. @abondar can you re-review? |
|
Can you please try instead of your fix to both client and wrapper - to make such fix to transaction wrapper? There is a chance that all problems we are having are just because transactional wrapper doesn't have proper cursor closing, and as tests are running in heavy transaction enviroment - tests are flaking because of it |
@abondar I think you're right! I opened this PR and it seems to be working: #2171 |
|
We implemented a better solution in #2171 |
Description
We recently see a lot of these errors in MSSQL CI which relies on
pyodbc:bulk_createroutes throughexecute_many, which usescursor.executemany(). By default, MSSQL sends a "rows affected" message after each statement executed byexecutemany. These messages accumulate as pending result sets on the connection, and since they are never consumed, the connection is left in a busy state when returned to the pool, causing the next operation to fail.The fix is to override
execute_manyinMSSQLClientto replacecursor.executemany()with an explicit loop of individualcursor.execute()calls, each prefixed withSET NOCOUNT ON. This suppresses the row-count messages at the source, preventing them from accumulating on the connection.NOTE: There is potentially a small performance cost from the extra Python overhead, but the inserted data will be identical.
Motivation and Context
Fix failing CI in MSSQL.
How Has This Been Tested?
Run MSSQL in CI and make sure the error doesn't show up.
Checklist: