Skip to content

Commit

Permalink
feat: Attempt to warm http2 connection upon SDK startup (#1201)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blaine-arcjet authored Jul 31, 2024
1 parent e44d81d commit a5c2571
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion transport/index.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}

0 comments on commit a5c2571

Please sign in to comment.