mirror of
https://github.com/denoland/deno.git
synced 2025-01-06 22:35:51 -05:00
A potential fix for @npmcli/agent
issue
If there's no listener for reading events to socket, then do not eagerly start reading the TcpConn.
This commit is contained in:
parent
c1054b88b2
commit
c47898e2b1
2 changed files with 17 additions and 4 deletions
|
@ -615,7 +615,7 @@ class ClientRequest extends OutgoingMessage {
|
||||||
_destroy(req, err || req[kError]);
|
_destroy(req, err || req[kError]);
|
||||||
} else {
|
} else {
|
||||||
// Note: this code is specific to deno to initiate a request.
|
// Note: this code is specific to deno to initiate a request.
|
||||||
socket.on("connect", () => {
|
const onConnect = () => {
|
||||||
// Flush the internal buffers once socket is ready.
|
// Flush the internal buffers once socket is ready.
|
||||||
// Note: the order is important, as the headers flush
|
// Note: the order is important, as the headers flush
|
||||||
// sets up the request.
|
// sets up the request.
|
||||||
|
@ -623,11 +623,14 @@ class ClientRequest extends OutgoingMessage {
|
||||||
this.once("requestReady", () => {
|
this.once("requestReady", () => {
|
||||||
this._flushBuffer();
|
this._flushBuffer();
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.emit("socket", socket);
|
this.emit("socket", socket);
|
||||||
// tickOnSocket(req, socket);
|
if (socket.readyState === "opening") {
|
||||||
// req._flush();
|
socket.on("connect", onConnect);
|
||||||
|
} else {
|
||||||
|
onConnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,6 +363,16 @@ function _afterConnect(
|
||||||
socket.emit("connect");
|
socket.emit("connect");
|
||||||
socket.emit("ready");
|
socket.emit("ready");
|
||||||
|
|
||||||
|
// Note: This is Deno specific logic
|
||||||
|
// If there's no listener for the connect, ready, data event,
|
||||||
|
// we delay the first read. This is necessary for http.request to work properly.
|
||||||
|
const connectListeners = socket.listenerCount("connect");
|
||||||
|
const readyListeners = socket.listenerCount("ready");
|
||||||
|
const dataListeners = socket.listenerCount("data");
|
||||||
|
if (connectListeners === 0 && readyListeners === 0 && dataListeners === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Start the first read, or get an immediate EOF.
|
// Start the first read, or get an immediate EOF.
|
||||||
// this doesn't actually consume any bytes, because len=0.
|
// this doesn't actually consume any bytes, because len=0.
|
||||||
if (readable && !socket.isPaused()) {
|
if (readable && !socket.isPaused()) {
|
||||||
|
|
Loading…
Reference in a new issue