diff --git a/libs/http2-manager/src/HTTP2/Client/Manager.hs b/libs/http2-manager/src/HTTP2/Client/Manager.hs index 2cf1278061..b163b7fdf0 100644 --- a/libs/http2-manager/src/HTTP2/Client/Manager.hs +++ b/libs/http2-manager/src/HTTP2/Client/Manager.hs @@ -11,6 +11,7 @@ module HTTP2.Client.Manager defaultHttp2Manager, http2ManagerWithSSLCtx, withHTTP2Request, + withHTTP2RequestOnSingleUseConn, connectIfNotAlreadyConnected, ConnectionAlreadyClosed (..), disconnectTarget, diff --git a/libs/http2-manager/src/HTTP2/Client/Manager/Internal.hs b/libs/http2-manager/src/HTTP2/Client/Manager/Internal.hs index 884bc46959..0dd00173c8 100644 --- a/libs/http2-manager/src/HTTP2/Client/Manager/Internal.hs +++ b/libs/http2-manager/src/HTTP2/Client/Manager/Internal.hs @@ -165,6 +165,15 @@ withHTTP2Request mgr target req k = do conn <- getOrMakeConnection mgr target sendRequestWithConnection conn req k +-- | Temporary workaround for https://github.com/kazu-yamamoto/http2/issues/102 +withHTTP2RequestOnSingleUseConn :: Http2Manager -> Target -> HTTP2.Request -> (HTTP2.Response -> IO a) -> IO a +withHTTP2RequestOnSingleUseConn Http2Manager {..} target req k = do + sendReqMVar <- newEmptyMVar + thread <- liftIO . async $ startPersistentHTTP2Connection sslContext target cacheLimit sslRemoveTrailingDot tcpConnectionTimeout sendReqMVar + let newConn = HTTP2Conn thread (putMVar sendReqMVar CloseConnection) sendReqMVar + sendRequestWithConnection newConn req $ \resp -> do + k resp <* disconnect newConn + -- | Connects to a server if it is not already connected, useful when making -- many concurrent requests. This way the first few requests don't have to fight -- for making a connection This way the first few requests don't have to fight diff --git a/services/federator/src/Federator/Remote.hs b/services/federator/src/Federator/Remote.hs index 21f1443c78..7f1b880dbe 100644 --- a/services/federator/src/Federator/Remote.hs +++ b/services/federator/src/Federator/Remote.hs @@ -101,7 +101,7 @@ interpretRemote = interpret $ \case resp <- mapError (RemoteError target pathT) . (fromEither @FederatorClientHTTP2Error =<<) . embed $ Codensity $ \k -> E.catches - (H2Manager.withHTTP2Request mgr (True, hostname, fromIntegral port) req' (consumeStreamingResponseWith $ k . Right)) + (H2Manager.withHTTP2RequestOnSingleUseConn mgr (True, hostname, fromIntegral port) req' (consumeStreamingResponseWith $ k . Right)) [ E.Handler $ k . Left, E.Handler $ k . Left . FederatorClientTLSException, E.Handler $ k . Left . FederatorClientHTTP2Exception,