@@ -263,30 +263,34 @@ impl Connection {
263263
264264impl Drop for Connection {
265265 fn drop ( & mut self ) {
266- if self . command_executing {
267- self . close ( ConnectionClosedReason :: Dropped ) ;
268- } else {
269- // If the connection has a weak reference to a pool, that means that the connection is
270- // being dropped when it's checked out. If the pool is still alive, it
271- // should check itself back in. Otherwise, the connection should close
272- // itself and emit a ConnectionClosed event (because the `close_and_drop`
273- // helper was not called explicitly).
274- //
275- // If the connection does not have a weak reference to a pool, then the connection is
276- // being dropped while it's not checked out. This means that the pool called
277- // the `close_and_drop` helper explicitly, so we don't add it back to the
278- // pool or emit any events.
279- if let Some ( ref weak_pool_ref) = self . pool {
280- if let Some ( strong_pool_ref) = weak_pool_ref. upgrade ( ) {
281- let dropped_connection_state = self . take ( ) ;
282- RUNTIME . execute ( async move {
266+ let command_executing = self . command_executing ;
267+
268+ // If the connection has a weak reference to a pool, that means that the connection is
269+ // being dropped when it's checked out. If the pool is still alive, it
270+ // should check itself back in. Otherwise, the connection should close
271+ // itself and emit a ConnectionClosed event (because the `close_and_drop`
272+ // helper was not called explicitly).
273+ //
274+ // If the connection does not have a weak reference to a pool, then the connection is
275+ // being dropped while it's not checked out. This means that the pool called
276+ // the `close_and_drop` helper explicitly, so we don't add it back to the
277+ // pool or emit any events.
278+ if let Some ( ref weak_pool_ref) = self . pool {
279+ if let Some ( strong_pool_ref) = weak_pool_ref. upgrade ( ) {
280+ let dropped_connection_state = self . take ( ) ;
281+ RUNTIME . execute ( async move {
282+ if command_executing {
283+ strong_pool_ref
284+ . dropped ( dropped_connection_state. into ( ) )
285+ . await ;
286+ } else {
283287 strong_pool_ref
284288 . check_in ( dropped_connection_state. into ( ) )
285289 . await ;
286- } ) ;
287- } else {
288- self . close ( ConnectionClosedReason :: PoolClosed ) ;
289- }
290+ }
291+ } ) ;
292+ } else {
293+ self . close ( ConnectionClosedReason :: PoolClosed ) ;
290294 }
291295 }
292296 }
0 commit comments