asyncmy icon indicating copy to clipboard operation
asyncmy copied to clipboard

handle connection close on CancelledError to prevent stale results

Open shenchucheng opened this issue 1 year ago • 3 comments

Description

This PR resolves an issue where canceled queries using connections from a pool leave unintended results that affect subsequent queries. When a query is canceled, the connection is returned to the pool without proper cleanup, causing future queries to receive residual data from the canceled task.

Solution

  • Implemented _close_on_cancel to ensure that connections are fully closed and reset when a query is canceled.
  • Added a test case to verify that canceled queries do not impact future connections from the pool.

This update ensures clean connection states on cancellation, improving reliability in pooled query operations. This approach is inspired by similar handling in aiomysql

Related Issues

  • Fixes #100
  • Fixes #103

shenchucheng avatar Nov 14 '24 12:11 shenchucheng

Please run make style ci in local first

long2ice avatar Nov 14 '24 12:11 long2ice

Please run make style ci in local first

Okay, I've updated it. Please check again.

shenchucheng avatar Nov 14 '24 13:11 shenchucheng

Cool, we need this fix, could you please prioritize it? I have to use a forked version now cannot receive update friendly ...

StrayDragon avatar Aug 20 '25 08:08 StrayDragon