From a5c25719e1a9dab4658a6a7c736f14b405ecff1e Mon Sep 17 00:00:00 2001 From: blaine-arcjet <146491715+blaine-arcjet@users.noreply.github.com> Date: Wed, 31 Jul 2024 06:18:28 -0700 Subject: [PATCH] feat: Attempt to warm http2 connection upon SDK startup (#1201) This updates our HTTP2 transport to attempt the `connect()` of the HTTP2 connection upon initialization. It also sets a 600 second timeout on the connection. This most benefits long-running servers, but improvements can also be seen in warm serverless functions. --- transport/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/transport/index.ts b/transport/index.ts index bee8d3880..0c0eaf668 100644 --- a/transport/index.ts +++ b/transport/index.ts @@ -1,8 +1,21 @@ -import { createConnectTransport } from "@connectrpc/connect-node"; +import { + createConnectTransport, + Http2SessionManager, +} from "@connectrpc/connect-node"; export function createTransport(baseUrl: string) { + // We create our own session manager so we can attempt to pre-connect + const sessionManager = new Http2SessionManager(baseUrl, { + // AWS ALB doesn't support PING so we use a very high idle timeout + idleConnectionTimeoutMs: 600 * 1000, + }); + + // We ignore the promise result because this is an optimistic pre-connect + sessionManager.connect(); + return createConnectTransport({ baseUrl, httpVersion: "2", + sessionManager, }); }