1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(net): don't try to set nodelay on upgrade streams (#26342)

Fixes https://github.com/denoland/deno/issues/26341.

We try to call `op_set_nodelay` on an `UpgradeStream`, which doesn't
support that operation.
This commit is contained in:
Nathan Whitaker 2024-10-16 20:56:57 -07:00 committed by GitHub
parent 167f674c7c
commit a61ba3c699
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 5 deletions

View file

@ -76,7 +76,11 @@ import {
ReadableStreamPrototype, ReadableStreamPrototype,
resourceForReadableStream, resourceForReadableStream,
} from "ext:deno_web/06_streams.js"; } from "ext:deno_web/06_streams.js";
import { listen, listenOptionApiName, TcpConn } from "ext:deno_net/01_net.js"; import {
listen,
listenOptionApiName,
UpgradedConn,
} from "ext:deno_net/01_net.js";
import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js"; import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js";
import { SymbolAsyncDispose } from "ext:deno_web/00_infra.js"; import { SymbolAsyncDispose } from "ext:deno_web/00_infra.js";
@ -189,7 +193,7 @@ class InnerRequest {
const upgradeRid = op_http_upgrade_raw(external); const upgradeRid = op_http_upgrade_raw(external);
const conn = new TcpConn( const conn = new UpgradedConn(
upgradeRid, upgradeRid,
underlyingConn?.remoteAddr, underlyingConn?.remoteAddr,
underlyingConn?.localAddr, underlyingConn?.localAddr,

View file

@ -194,6 +194,20 @@ class Conn {
} }
} }
class UpgradedConn extends Conn {
#rid = 0;
constructor(rid, remoteAddr, localAddr) {
super(rid, remoteAddr, localAddr);
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
this.#rid = rid;
}
}
class TcpConn extends Conn { class TcpConn extends Conn {
#rid = 0; #rid = 0;
@ -601,5 +615,6 @@ export {
resolveDns, resolveDns,
TcpConn, TcpConn,
UnixConn, UnixConn,
UpgradedConn,
validatePort, validatePort,
}; };

View file

@ -67,7 +67,7 @@ import { headersEntries } from "ext:deno_fetch/20_headers.js";
import { timerId } from "ext:deno_web/03_abort_signal.js"; import { timerId } from "ext:deno_web/03_abort_signal.js";
import { clearTimeout as webClearTimeout } from "ext:deno_web/02_timers.js"; import { clearTimeout as webClearTimeout } from "ext:deno_web/02_timers.js";
import { resourceForReadableStream } from "ext:deno_web/06_streams.js"; import { resourceForReadableStream } from "ext:deno_web/06_streams.js";
import { TcpConn } from "ext:deno_net/01_net.js"; import { UpgradedConn } from "ext:deno_net/01_net.js";
import { STATUS_CODES } from "node:_http_server"; import { STATUS_CODES } from "node:_http_server";
import { methods as METHODS } from "node:_http_common"; import { methods as METHODS } from "node:_http_common";
@ -517,7 +517,7 @@ class ClientRequest extends OutgoingMessage {
); );
assert(typeof res.remoteAddrIp !== "undefined"); assert(typeof res.remoteAddrIp !== "undefined");
assert(typeof res.remoteAddrIp !== "undefined"); assert(typeof res.remoteAddrIp !== "undefined");
const conn = new TcpConn( const conn = new UpgradedConn(
upgradeRid, upgradeRid,
{ {
transport: "tcp", transport: "tcp",

View file

@ -300,7 +300,9 @@ export class TCP extends ConnectionWrap {
* @return An error status code. * @return An error status code.
*/ */
setNoDelay(noDelay: boolean): number { setNoDelay(noDelay: boolean): number {
if ("setNoDelay" in this[kStreamBaseField]) {
this[kStreamBaseField].setNoDelay(noDelay); this[kStreamBaseField].setNoDelay(noDelay);
}
return 0; return 0;
} }