From 7402ae61d9cb0fc5b09ea05a9cad8ed7a886490b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Jul 2024 11:03:18 -0400 Subject: [PATCH] fix reversion in GET from proxy over http 4f3ae966662c38080fcafb9d5bbee4dedce566b8 caused a hang in GET, which git-annex testremote could reliably cause. The problem is that closing both P2P handles before waiting on the asyncworker prevents all the DATA from getting sent. The solution is to only close the P2P handles early when the P2PConnection is being closed. When it's being released, let the asyncworker finish. closeP2PConnection is called in GET when it was unable to send all data, and in PUT when it did not receive all the data, and in both cases closing the P2P handles early is ok. --- P2P/Http/State.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/P2P/Http/State.hs b/P2P/Http/State.hs index f52614b6c8..7e43df81de 100644 --- a/P2P/Http/State.hs +++ b/P2P/Http/State.hs @@ -378,12 +378,18 @@ proxyConnection proxyconnectionpoolsize relv connparams workerpool proxypool pro liftIO $ runNetProto proxyfromclientrunst proxyfromclientconn $ P2P.net P2P.receiveMessage - let releaseconn returntopool = do + let closebothsides = do + liftIO $ closeConnection proxyfromclientconn + liftIO $ closeConnection clientconn + + let releaseconn connstillusable = do atomically $ void $ tryPutTMVar relv $ do - liftIO $ closeConnection proxyfromclientconn - liftIO $ closeConnection clientconn + unless connstillusable + closebothsides r <- liftIO $ wait asyncworker - if returntopool + when connstillusable + closebothsides + if connstillusable then liftIO $ do now <- getPOSIXTime evicted <- atomically $ putProxyConnectionPool proxypool proxyconnectionpoolsize connparams $