Skip to content

Commit

Permalink
Try latest http2 library and star re-using connections again
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaymankar committed Jul 15, 2024
1 parent 71a30ab commit bba3c8b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
2 changes: 0 additions & 2 deletions libs/wire-api-federation/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
, aeson
, aeson-pretty
, amqp
, async
, base
, bytestring
, bytestring-conversion
Expand Down Expand Up @@ -54,7 +53,6 @@ mkDerivation {
libraryHaskellDepends = [
aeson
amqp
async
base
bytestring
bytestring-conversion
Expand Down
22 changes: 3 additions & 19 deletions libs/wire-api-federation/src/Wire/API/Federation/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module Wire.API.Federation.Client
)
where

import Control.Concurrent.Async
import Control.Exception qualified as E
import Control.Monad.Catch
import Control.Monad.Codensity
Expand Down Expand Up @@ -63,7 +62,6 @@ import Network.HTTP.Media qualified as HTTP
import Network.HTTP.Types qualified as HTTP
import Network.HTTP2.Client qualified as HTTP2
import Network.Wai.Utilities.Error qualified as Wai
import OpenSSL.Session qualified as SSL
import Servant.Client
import Servant.Client.Core
import Servant.Types.SourceT
Expand Down Expand Up @@ -123,27 +121,13 @@ liftCodensity = FederatorClient . lift . lift . lift
headersFromTable :: HTTP2.TokenHeaderTable -> [HTTP.Header]
headersFromTable (headerList, _) = flip map headerList $ first HTTP2.tokenKey

-- This opens a new http2 connection. Using a http2-manager leads to this problem https://wearezeta.atlassian.net/browse/WPB-4787
-- FUTUREWORK: Replace with H2Manager.withHTTP2Request once the bugs are solved.
withNewHttpRequest :: H2Manager.Target -> HTTP2.Request -> (HTTP2.Response -> IO a) -> IO a
withNewHttpRequest target req k = do
ctx <- SSL.context
let cacheLimit = 20
sslRemoveTrailingDot = False
tcpConnectionTimeout = 30_000_000
sendReqMVar <- newEmptyMVar
thread <- liftIO . async $ H2Manager.startPersistentHTTP2Connection ctx target cacheLimit sslRemoveTrailingDot tcpConnectionTimeout sendReqMVar
let newConn = H2Manager.HTTP2Conn thread (putMVar sendReqMVar H2Manager.CloseConnection) sendReqMVar
H2Manager.sendRequestWithConnection newConn req $ \resp -> do
k resp <* newConn.disconnect

performHTTP2Request ::
Http2Manager ->
H2Manager.Target ->
HTTP2.Request ->
IO (Either FederatorClientHTTP2Error (ResponseF Builder))
performHTTP2Request _mgr target req = try $ do
withNewHttpRequest target req $ consumeStreamingResponseWith $ \resp -> do
performHTTP2Request mgr target req = try $ do
H2Manager.withHTTP2Request mgr target req $ consumeStreamingResponseWith $ \resp -> do
b <-
fmap (fromRight mempty)
. runExceptT
Expand Down Expand Up @@ -250,7 +234,7 @@ withHTTP2StreamingRequest successfulStatus req handleResponse = do
$ Codensity
$ \k ->
E.catches
(withNewHttpRequest (False, hostname, port) req' (consumeStreamingResponseWith (k . Right)))
(H2Manager.withHTTP2Request env.ceHttp2Manager (False, hostname, port) req' (consumeStreamingResponseWith (k . Right)))
[ E.Handler $ k . Left . FederatorClientHTTP2Error,
E.Handler $ k . Left . FederatorClientHTTP2Error . FederatorClientConnectionError,
E.Handler $ k . Left . FederatorClientHTTP2Error . FederatorClientHTTP2Exception,
Expand Down
1 change: 0 additions & 1 deletion libs/wire-api-federation/wire-api-federation.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ library
build-depends:
aeson >=2.0.1.0
, amqp
, async
, base >=4.6 && <5.0
, bytestring
, bytestring-conversion
Expand Down
30 changes: 17 additions & 13 deletions nix/haskell-pins.nix
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,23 @@ let
};
};

http2 = {
src = pkgs.fetchFromGitHub {
owner = "kazu-yamamoto";
repo = "http2";
rev = "90dde392d8d0edba77c66fe99966267ed9369c30";
hash = "sha256-RkvJxpMkNbDGSPkjt+h5smhe1cr6bnqYeAfyc5YbwIU=";
};
};

http-semantics = {
src = pkgs.fetchFromGitHub {
owner = "kazu-yamamoto";
repo = "http-semantics";
rev = "d4315ba8d4d23ec09a7642064d20353a296ceb89";
hash = "sha256-ChpXT+FMqdm2WkEBR1hq4cjKPj3WmjeePvTnQgcJzlM=";
};
};
};

hackagePins = {
Expand All @@ -281,19 +298,6 @@ let
};

# start pinned dependencies for http2

# this contains an important fix to the initialization of the window size
# and should be switched to upstream as soon as we can
http2 = {
version = "5.2.5";
sha256 = "sha256-FCd4lPydwWqm2lrhgYtPW+BuXGqmmA8KFrB87SYEowY=";
};

http-semantics = {
version = "0.1.2";
sha256 = "sha256-S4rGBCIKVPpLPumLcVzrPONrbWm8VBizqxI3dXNIfr0=";
};

network-run = {
version = "0.3.0";
sha256 = "sha256-FP2GZKwacC+TLLwEIVgKBtnKplYPf5xOIjDfvlbQV0o=";
Expand Down
6 changes: 5 additions & 1 deletion nix/manual-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ hself: hsuper: {
tls = hsuper.tls_2_0_5;
tls-session-manager = hsuper.tls-session-manager_0_0_5;

# http-semantics is not released with the right version yet, but http2 bounds
# have already changed.
http2 = hlib.doJailbreak hsuper.http2;

# warp requires curl in its testsuite
warp = hlib.addTestToolDepends hsuper.warp [ curl ];
warp = hlib.doJailbreak (hlib.addTestToolDepends hsuper.warp [ curl ]);

# -----------------
# flags and patches
Expand Down

0 comments on commit bba3c8b

Please sign in to comment.