From 2e741b69f7f3a7e9c7188017f451027b3db75372 Mon Sep 17 00:00:00 2001 From: Alexei Boronine Date: Sun, 3 Nov 2024 23:00:36 +0100 Subject: [PATCH] wip --- src/h2tunnel.test.ts | 31 ++++++++++++++++++++++++++++++- src/h2tunnel.ts | 6 +++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/h2tunnel.test.ts b/src/h2tunnel.test.ts index 9b2a386..abb0e52 100644 --- a/src/h2tunnel.test.ts +++ b/src/h2tunnel.test.ts @@ -6,6 +6,7 @@ import { TunnelServer, } from "./h2tunnel.js"; import net from "node:net"; +import * as http2 from "node:http2"; // localhost HTTP1 server "python3 -m http.server" const LOCAL_PORT = 14000; @@ -422,7 +423,7 @@ await test( }, ); -await test.only("happy-path", { timeout: 5000 }, async (t) => { +await test("happy-path", { timeout: 5000 }, async (t) => { const echo = new EchoServer(LOCAL_PORT, PROXY_PORT); await echo.startAndWaitUntilReady(); @@ -545,3 +546,31 @@ await test("garbage-to-server", { timeout: 5000 }, async (t: TestContext) => { await server.stop(); await echoServer.stopAndWaitUntilClosed(); }); + +// await test.only("http2", { timeout: 5000 }, async (t: TestContext) => { +// const server = http2.createServer(); +// server.on("stream", (serverStream) => { +// serverStream.on("data", (chunk) => +// console.log("got data", chunk.toString("utf-8")), +// ); +// serverStream.on("error", (error) => { +// console.log("error", error); +// }); +// serverStream.on("close", () => { +// console.log("close"); +// }); +// serverStream.on("end", () => { +// console.log("end"); +// }); +// }); +// server.listen(16000, () => { +// const session = http2.connect(`http://localhost:${16000}`); +// session.on("connect", () => { +// const clientStream = session.request({ +// [http2.constants.HTTP2_HEADER_METHOD]: "POST", +// }); +// clientStream.write("a"); +// clientStream.close(http2.constants.NGHTTP2_INTERNAL_ERROR); +// }); +// }); +// }); diff --git a/src/h2tunnel.ts b/src/h2tunnel.ts index 3d9c2bd..4ed20c9 100644 --- a/src/h2tunnel.ts +++ b/src/h2tunnel.ts @@ -165,17 +165,17 @@ export abstract class AbstractTunnel< log({ [tag]: "end" }); // 'end' comes before 'error', so we need to wait make sure 'error' doesn't come it before processing 'end' // https://github.com/nodejs/node/issues/39400 - endTimeout = setTimeout(() => { + setImmediate(() => { if (!duplex2.writableEnded) { log({ [tag]: "closing opposite" }); duplex2.end(); } - }, 50); + }); }); duplex1.on("close", () => { log({ [tag]: "close" }); - if (duplex1.errored && !duplex2.destroyed) { + if (duplex1.errored && !duplex2.closed) { if (endTimeout) { clearTimeout(endTimeout); }