diff --git a/package-lock.json b/package-lock.json index e31a69bcbb..67851f0ffb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,7 +67,7 @@ "ts-node": "^10.9.2", "tsd": "^0.31.1", "typescript": "^5.5.3", - "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.30.0", + "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.48.0", "wdio-geckodriver-service": "^5.0.2" } }, @@ -14207,9 +14207,10 @@ } }, "node_modules/uWebSockets.js": { - "version": "20.30.0", - "resolved": "git+ssh://git@github.com/uNetworking/uWebSockets.js.git#d39d4181daf5b670d44cbc1b18f8c28c85fd4142", - "dev": true + "version": "20.48.0", + "resolved": "git+ssh://git@github.com/uNetworking/uWebSockets.js.git#51ae1d1fd92dff77cbbdc7c431021f85578da1a6", + "dev": true, + "license": "Apache-2.0" }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", diff --git a/package.json b/package.json index d10a0029bf..5ce5b3fc8f 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "ts-node": "^10.9.2", "tsd": "^0.31.1", "typescript": "^5.5.3", - "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.30.0", + "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.48.0", "wdio-geckodriver-service": "^5.0.2" } } diff --git a/packages/engine.io/test/common.js b/packages/engine.io/test/common.js index 72b254a328..136395fbbb 100644 --- a/packages/engine.io/test/common.js +++ b/packages/engine.io/test/common.js @@ -4,6 +4,17 @@ const { Socket } = ? require("engine.io-client-v3") : require("engine.io-client"); +switch (process.env.EIO_WS_ENGINE) { + case "uws": + console.log( + "[WARN] testing with uWebSockets.js instead of Node.js built-in HTTP server", + ); + break; + case "eiows": + console.log("[WARN] testing with eiows instead of ws"); + break; +} + /** * Listen shortcut that fires a callback on an ephemeral port. */ diff --git a/packages/engine.io/test/server.js b/packages/engine.io/test/server.js index 35b1988357..898e53f673 100644 --- a/packages/engine.io/test/server.js +++ b/packages/engine.io/test/server.js @@ -817,7 +817,7 @@ describe("server", () => { .end((err, res) => { if (process.env.EIO_WS_ENGINE === "uws") { expect(err).to.not.be(null); - expect(err.message).to.be("socket hang up"); + expect(err.status).to.be(404); } else { expect(err).to.be(null); // this should not work, but it is kept for backward-compatibility diff --git a/packages/socket.io/lib/uws.ts b/packages/socket.io/lib/uws.ts index 89a6bf7d33..14bcc0aebb 100644 --- a/packages/socket.io/lib/uws.ts +++ b/packages/socket.io/lib/uws.ts @@ -135,25 +135,27 @@ export function serveFile(res /* : HttpResponse */, filepath: string) { const onDataChunk = (chunk: Buffer) => { const arrayBufferChunk = toArrayBuffer(chunk); - const lastOffset = res.getWriteOffset(); - const [ok, done] = res.tryEnd(arrayBufferChunk, size); + res.cork(() => { + const lastOffset = res.getWriteOffset(); + const [ok, done] = res.tryEnd(arrayBufferChunk, size); - if (!done && !ok) { - readStream.pause(); + if (!done && !ok) { + readStream.pause(); - res.onWritable((offset) => { - const [ok, done] = res.tryEnd( - arrayBufferChunk.slice(offset - lastOffset), - size, - ); + res.onWritable((offset) => { + const [ok, done] = res.tryEnd( + arrayBufferChunk.slice(offset - lastOffset), + size, + ); - if (!done && ok) { - readStream.resume(); - } + if (!done && ok) { + readStream.resume(); + } - return ok; - }); - } + return ok; + }); + } + }); }; res.onAborted(destroyReadStream);