调用外部服务前update事务未提交致查询超时,事务提交存疑求助
Yesterday I posted a question with the same title on Stack Overflow, but after deeper investigation, I realized the actual issue differs from my initial understanding—so I'm re-posting to get clearer guidance.
Here's what's happening based on our database monitoring tool screenshots:
- My Java app sent three green queries in sequence:
- A stored procedure containing select statements
- A stored procedure with two
UPDATEoperations onMyTable - A direct select query on
MyTable
Right after these, we called an external service. Its select query on MyTable (marked red in the monitor) timed out because it couldn't access the table.
I tried modifying the second update-containing stored procedure to commit changes before the external service call, with these attempts:
Only wrap the updates in a basic stored procedure:
CREATE PROCEDURE ... AS BEGIN UPDATE .... UPDATE .... ENDThe external query still timed out.
Wrap the updates in an explicit transaction and commit inside the procedure:
Still no luck—external query kept timing out.Add a commit for existing transactions at the end of the procedure:
When I added this line to the end of the procedure, the external query finally stopped timing out:IF @@TRANCOUNT > 0 COMMIT TRANBut this feels risky because I don't know where the transaction was originally started. Committing an unaccounted-for transaction isn't a safe long-term fix.
I'm stuck at this point and don't know how to proceed with troubleshooting. Could anyone share some debugging ideas or practical solutions?
内容的提问来源于stack exchange,提问作者wwwww

