From 167723a9e357897b9fb7a79c7f67dc5d2ed4477d Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Fri, 30 Aug 2024 13:32:34 +0200 Subject: [PATCH] Update other servers Signed-off-by: Timo Stamm --- .../connect-express/conformance/server.ts | 13 +++++----- .../connect-fastify/conformance/server.ts | 13 +++++----- packages/connect-node/conformance/server.ts | 24 +++---------------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/packages/connect-express/conformance/server.ts b/packages/connect-express/conformance/server.ts index 4681cd8e0..ccd65a1f1 100755 --- a/packages/connect-express/conformance/server.ts +++ b/packages/connect-express/conformance/server.ts @@ -31,6 +31,7 @@ import { ServerCompatResponse, ServerStreamRequest, UnaryRequest, + writeSizeDelimitedBuffer, } from "@connectrpc/connect-conformance"; import express from "express"; import { expressConnectMiddleware } from "../src/index.js"; @@ -104,8 +105,12 @@ function main() { } process.on("SIGTERM", () => { - server.close(); + // Gracefully shutting down a http2 server is complicated. + // We trust the conformance test runner to only send the SIGNAL if it's done, + // so we simply shut down hard. + process.exit(); }); + server.listen(undefined, "127.0.0.1", () => { const addrInfo = server.address() as net.AddressInfo; const res = new ServerCompatResponse({ @@ -116,10 +121,6 @@ function main() { host: addrInfo.address, port: addrInfo.port, }); - const data = res.toBinary(); - const size = Buffer.alloc(4); - size.writeUInt32BE(data.byteLength); - process.stdout.write(size); - process.stdout.write(data); + process.stdout.write(writeSizeDelimitedBuffer(res.toBinary())); }); } diff --git a/packages/connect-fastify/conformance/server.ts b/packages/connect-fastify/conformance/server.ts index 02c33894f..1d904d12a 100755 --- a/packages/connect-fastify/conformance/server.ts +++ b/packages/connect-fastify/conformance/server.ts @@ -30,6 +30,7 @@ import { ServerCompatResponse, ServerStreamRequest, UnaryRequest, + writeSizeDelimitedBuffer, } from "@connectrpc/connect-conformance"; import { fastify } from "fastify"; import type { @@ -136,8 +137,12 @@ function main() { } process.on("SIGTERM", () => { - void server.close(); + // Gracefully shutting down a http2 server is complicated. + // We trust the conformance test runner to only send the SIGNAL if it's done, + // so we simply shut down hard. + process.exit(); }); + server.listen({ host: "127.0.0.1", port: 0 }, () => { const addrInfo = server.addresses()[0]; const res = new ServerCompatResponse({ @@ -148,10 +153,6 @@ function main() { host: addrInfo.address, port: addrInfo.port, }); - const data = res.toBinary(); - const size = Buffer.alloc(4); - size.writeUInt32BE(data.byteLength); - process.stdout.write(size); - process.stdout.write(data); + process.stdout.write(writeSizeDelimitedBuffer(res.toBinary())); }); } diff --git a/packages/connect-node/conformance/server.ts b/packages/connect-node/conformance/server.ts index 35b0cf220..48ae9e3c0 100755 --- a/packages/connect-node/conformance/server.ts +++ b/packages/connect-node/conformance/server.ts @@ -40,11 +40,6 @@ import { main(); -process.on("exit", () => { - console.error(process.pid, "connect-node/conformance/server.ts exit"); -}); - - /** * This program implements a server under test for the connect conformance test * runner. It reads ServerCompatRequest messages from stdin, starts the server @@ -52,7 +47,6 @@ process.on("exit", () => { * server's port and other details to stdout. */ function main() { - console.error(process.pid, "connect-node/conformance/server.ts main()"); const req = ServerCompatRequest.fromBinary( readFileSync(process.stdin.fd).subarray(4), ); @@ -95,7 +89,6 @@ function main() { }; } } - const h2Sessions = new Set(); switch (req.httpVersion) { case HTTPVersion.HTTP_VERSION_1: server = req.useTls @@ -106,7 +99,6 @@ function main() { server = req.useTls ? http2.createSecureServer(serverOptions, adapter) : http2.createServer(adapter); - server.on("session", s => h2Sessions.add(s)); break; case HTTPVersion.HTTP_VERSION_3: throw new Error("HTTP/3 is not supported"); @@ -115,20 +107,10 @@ function main() { } process.on("SIGTERM", () => { + // Gracefully shutting down a http2 server is complicated. + // We trust the conformance test runner to only send the SIGNAL if it's done, + // so we simply shut down hard. process.exit(); - // if ("closeAllConnections" in server) { - // console.error(process.pid, "connect-node/conformance/server.ts SIGTERM", "h1"); - // server.closeAllConnections(); - // server.close(); - // } else { - // console.error(process.pid, "connect-node/conformance/server.ts SIGTERM", "h2"); - // for (const s of h2Sessions) { - // if (!s.closed) { - // s.close(); - // } - // } - // server.close(); - // } }); server.listen(0, "127.0.0.1", () => {