1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-05 13:59:01 -05:00

remove workaround using linsterCount as it didn't work.

Instead use workaround reading callstack in `connect()` call and
pause the socket when it's from @npmcli/agent. This prevents the
undesirable initial read of the socket.
This commit is contained in:
Yoshiya Hinosawa 2024-10-25 13:06:28 +09:00
parent 8ece841314
commit d777191e33
No known key found for this signature in database
GPG key ID: 9017DB4559488785

View file

@ -360,21 +360,9 @@ function _afterConnect(
socket._unrefTimer();
const connectListeners = socket.listenerCount("connect");
const readyListeners = socket.listenerCount("ready");
const dataListeners = socket.listenerCount("data");
socket.emit("connect");
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.
// See https://github.com/denoland/deno/pull/25470#issuecomment-2435077722
if (connectListeners === 0 && readyListeners === 0 && dataListeners === 0) {
return;
}
// Start the first read, or get an immediate EOF.
// this doesn't actually consume any bytes, because len=0.
if (readable && !socket.isPaused()) {
@ -1598,6 +1586,15 @@ export function connect(...args: unknown[]) {
debug("createConnection", normalized);
const socket = new Socket(options);
// If it's called from @npmcli/agent, 'connect' event on Socket happens
// before 'socket' event on ClientRequst, and that causes initial read
// happening before op_node_http_request_with_conn(), and http reqeust
// doesn't work. The below pause() call prevent that initial read for
// @npmcli/agent.
if (new Error().stack?.includes("@npmcli/agent")) {
socket.pause();
}
if (netClientSocketChannel.hasSubscribers) {
netClientSocketChannel.publish({
socket,