fix releasing of p2p connection

This commit is contained in:
Joey Hess 2024-07-22 11:26:22 -04:00
parent 72d0769ca5
commit 726c815a7f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 31 additions and 14 deletions

View file

@ -322,7 +322,7 @@ serveCheckPresent
-> Maybe Auth -> Maybe Auth
-> Handler CheckPresentResult -> Handler CheckPresentResult
serveCheckPresent st su apiver (B64Key k) cu bypass sec auth = do serveCheckPresent st su apiver (B64Key k) cu bypass sec auth = do
res <- withP2PConnection apiver st cu su bypass sec auth ReadAction res <- withP2PConnection apiver st cu su bypass sec auth ReadAction id
$ \conn -> liftIO $ proxyClientNetProto conn $ checkPresent k $ \conn -> liftIO $ proxyClientNetProto conn $ checkPresent k
case res of case res of
Right b -> return (CheckPresentResult b) Right b -> return (CheckPresentResult b)
@ -373,7 +373,7 @@ serveRemove
-> Maybe Auth -> Maybe Auth
-> Handler t -> Handler t
serveRemove st resultmangle su apiver (B64Key k) cu bypass sec auth = do serveRemove st resultmangle su apiver (B64Key k) cu bypass sec auth = do
res <- withP2PConnection apiver st cu su bypass sec auth RemoveAction res <- withP2PConnection apiver st cu su bypass sec auth RemoveAction id
$ \conn -> $ \conn ->
liftIO $ proxyClientNetProto conn $ remove Nothing k liftIO $ proxyClientNetProto conn $ remove Nothing k
case res of case res of
@ -429,7 +429,7 @@ serveRemoveBefore
-> Maybe Auth -> Maybe Auth
-> Handler RemoveResultPlus -> Handler RemoveResultPlus
serveRemoveBefore st su apiver (B64Key k) cu bypass (Timestamp ts) sec auth = do serveRemoveBefore st su apiver (B64Key k) cu bypass (Timestamp ts) sec auth = do
res <- withP2PConnection apiver st cu su bypass sec auth RemoveAction res <- withP2PConnection apiver st cu su bypass sec auth RemoveAction id
$ \conn -> $ \conn ->
liftIO $ proxyClientNetProto conn $ liftIO $ proxyClientNetProto conn $
removeBeforeRemoteEndTime ts k removeBeforeRemoteEndTime ts k
@ -481,7 +481,7 @@ serveGetTimestamp
-> Maybe Auth -> Maybe Auth
-> Handler GetTimestampResult -> Handler GetTimestampResult
serveGetTimestamp st su apiver cu bypass sec auth = do serveGetTimestamp st su apiver cu bypass sec auth = do
res <- withP2PConnection apiver st cu su bypass sec auth ReadAction res <- withP2PConnection apiver st cu su bypass sec auth ReadAction id
$ \conn -> $ \conn ->
liftIO $ proxyClientNetProto conn getTimestamp liftIO $ proxyClientNetProto conn getTimestamp
case res of case res of
@ -545,12 +545,12 @@ servePut st resultmangle su apiver (DataLength len) (B64Key k) cu bypass baf mof
let validitycheck = local $ runValidityCheck $ let validitycheck = local $ runValidityCheck $
liftIO $ atomically $ readTMVar validityv liftIO $ atomically $ readTMVar validityv
content <- liftIO $ S.unSourceT stream (gather validityv) content <- liftIO $ S.unSourceT stream (gather validityv)
conn <- getP2PConnection apiver st cu su bypass sec auth WriteAction $ res <- withP2PConnection' apiver st cu su bypass sec auth WriteAction
\st -> st { connectionWaitVar = False } (\st -> st { connectionWaitVar = False }) $ \conn ->
res <- liftIO $ inAnnexWorker st $ liftIO $ inAnnexWorker st $
enteringStage (TransferStage Download) $ enteringStage (TransferStage Download) $
runFullProto (clientRunState conn) (clientP2PConnection conn) $ runFullProto (clientRunState conn) (clientP2PConnection conn) $
protoaction content validitycheck protoaction content validitycheck
case res of case res of
Right (Right (Just plusuuids)) -> return $ resultmangle $ Right (Right (Just plusuuids)) -> return $ resultmangle $
PutResultPlus True (map B64UUID plusuuids) PutResultPlus True (map B64UUID plusuuids)

View file

@ -62,18 +62,35 @@ withP2PConnection
-> IsSecure -> IsSecure
-> Maybe Auth -> Maybe Auth
-> ActionClass -> ActionClass
-> (ConnectionParams -> ConnectionParams)
-> (P2PConnectionPair -> Handler (Either ProtoFailure a)) -> (P2PConnectionPair -> Handler (Either ProtoFailure a))
-> Handler a -> Handler a
withP2PConnection apiver st cu su bypass sec auth actionclass connaction = do withP2PConnection apiver st cu su bypass sec auth actionclass fconnparams connaction =
conn <- getP2PConnection apiver st cu su bypass sec auth actionclass id withP2PConnection' apiver st cu su bypass sec auth actionclass fconnparams connaction'
connaction' conn
`finally` liftIO (releaseP2PConnection conn)
where where
connaction' conn = connaction conn >>= \case connaction' conn = connaction conn >>= \case
Right r -> return r Right r -> return r
Left err -> throwError $ Left err -> throwError $
err500 { errBody = encodeBL (describeProtoFailure err) } err500 { errBody = encodeBL (describeProtoFailure err) }
withP2PConnection'
:: APIVersion v
=> v
-> P2PHttpServerState
-> B64UUID ClientSide
-> B64UUID ServerSide
-> [B64UUID Bypass]
-> IsSecure
-> Maybe Auth
-> ActionClass
-> (ConnectionParams -> ConnectionParams)
-> (P2PConnectionPair -> Handler a)
-> Handler a
withP2PConnection' apiver st cu su bypass sec auth actionclass fconnparams connaction = do
conn <- getP2PConnection apiver st cu su bypass sec auth actionclass fconnparams
connaction conn
`finally` liftIO (releaseP2PConnection conn)
getP2PConnection getP2PConnection
:: APIVersion v :: APIVersion v
=> v => v