From 4915f342b0ff391b5dcfbadc128cb54cf57add12 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 17 Oct 2024 12:10:06 +0900 Subject: [PATCH] remove debugs --- ext/node/ops/http.rs | 8 -- ext/node/polyfills/_http_outgoing.ts | 41 +---------- ext/node/polyfills/http.ts | 106 ++++++++------------------- 3 files changed, 32 insertions(+), 123 deletions(-) diff --git a/ext/node/ops/http.rs b/ext/node/ops/http.rs index 8462e2a35b..57e0530f40 100644 --- a/ext/node/ops/http.rs +++ b/ext/node/ops/http.rs @@ -118,7 +118,6 @@ where .take::(conn_rid)?; let resource = Rc::try_unwrap(resource_rc) .map_err(|_e| bad_resource("TLS stream is currently in use")); - eprintln!("op_node_http_request_with_conn(tls): {resource:?}"); let resource = resource?; let (read_half, write_half) = resource.into_inner(); let tcp_stream = read_half.unsplit(write_half); @@ -144,7 +143,6 @@ where .take::(conn_rid)?; let resource = Rc::try_unwrap(resource_rc) .map_err(|_| bad_resource("TCP stream is currently in use")); - eprintln!("op_node_http_request_with_conn(tcp): {resource:?}"); let resource = resource?; let (read_half, write_half) = resource.into_inner(); let tcp_stream = read_half.reunite(write_half)?; @@ -258,7 +256,6 @@ pub async fn op_node_http_wait_for_connection( .take::(rid)?; let resource = Rc::try_unwrap(resource).map_err(|_| bad_resource("NodeHttpConnReady")); - eprintln!("op_node_http_wait_for_connection: {resource:?}"); let resource = resource?; resource.recv.await?; Ok(rid) @@ -276,16 +273,12 @@ pub async fn op_node_http_await_response( .take::(rid)?; let resource = Rc::try_unwrap(resource) .map_err(|_| bad_resource("NodeHttpClientResponse")); - eprintln!("resource: {resource:?}"); let resource = resource?; - eprintln!("op_node_http_await_response: awating for res"); let res = resource.response.await; - eprintln!("op_node_http_await_response: res: {res:?}"); let res = res?; let status = res.status(); - eprintln!("op_node_http_await_response: {status}"); let mut res_headers = Vec::new(); for (key, val) in res.headers().iter() { res_headers.push((key.as_str().into(), val.as_bytes().into())); @@ -583,7 +576,6 @@ impl Stream for NodeHttpResourceToBodyAdapter { Ok(buf) if buf.is_empty() => Poll::Ready(None), Ok(buf) => { let bytes: Bytes = buf.to_vec().into(); - eprintln!("buf: {:?}", bytes); this.1 = Some(this.0.clone().read(64 * 1024)); Poll::Ready(Some(Ok(bytes))) } diff --git a/ext/node/polyfills/_http_outgoing.ts b/ext/node/polyfills/_http_outgoing.ts index 8bacf34b7d..e412ce7571 100644 --- a/ext/node/polyfills/_http_outgoing.ts +++ b/ext/node/polyfills/_http_outgoing.ts @@ -391,11 +391,7 @@ Object.defineProperties( msg._implicitHeader(); } - try { - return msg._send(chunk, encoding, callback); - } catch (error) { - console.log("error from msg._send()", error); - } + return msg._send(chunk, encoding, callback); }, // deno-lint-ignore no-explicit-any @@ -514,42 +510,23 @@ Object.defineProperties( /** Right after socket is ready, we need to writeHeader() to setup the request and * client. This is invoked by onSocket(). */ _flushHeaders() { - console.trace("_flushHeaders", { - socket: !!this.socket, - headerSent: this._headerSent, - }); - if (this.socket && !this._headerSent) { + if (!this._headerSent) { this._headerSent = true; this._writeHeader(); - } else { - // deno-lint-ignore no-console - console.warn("socket not found"); } - console.trace("_flushHeaders after", { - socket: !!this.socket, - headerSent: this._headerSent, - }); }, // deno-lint-ignore no-explicit-any _send(data: any, encoding?: string | null, callback?: () => void) { - console.trace("send invoked", { - data: new TextDecoder().decode(data.slice(-20, -1)), - }); // if socket is ready, write the data after headers are written. // if socket is not ready, buffer data in outputbuffer. if (this.socket && !this.socket.connecting) { - console.log("writing headers again:", { - headerSent: this._headerSent, - header: this._header, - }); if (!this._headerSent) { this._writeHeader(); this._headerSent = true; } if (this._headerSent) { - console.log("writeRaw invoked"); return this._writeRaw(data, encoding, callback); } } else { @@ -599,7 +576,6 @@ Object.defineProperties( encoding?: string | null, callback?: () => void, ) { - console.log("flushing data", data); if (typeof data === "string") { data = Buffer.from(data, encoding); } @@ -607,20 +583,9 @@ Object.defineProperties( data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); } if (data.buffer.byteLength > 0) { - console.log("waiting for bodyWriter to be ready", { - data: new TextDecoder().decode(data.slice(-20, -1)), - }); this._bodyWriter.ready.then(() => { - console.log("bodyWriter is ready", { - desirezedSize: this._bodyWriter.desiredSize, - }); if (this._bodyWriter.desiredSize > 0) { this._bodyWriter.write(data).then(() => { - console.log("writing done: ", { - last_bytes: new TextDecoder().decode(data.slice(-20, -1)), - length: data.length, - buffer: this.outputData.length, - }); callback?.(); if (this.outputData.length == 0) { this.emit("finish"); @@ -766,8 +731,6 @@ Object.defineProperties( const { header } = state; this._header = header + "\r\n"; - // console.log("_headerSent set to false"); - // this._headerSent = false; // Wait until the first body chunk, or close(), is sent to flush, // UNLESS we're sending Expect: 100-continue. diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 2bbfcb275c..3b3ade00e9 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -398,7 +398,6 @@ class ClientRequest extends OutgoingMessage { if (typeof optsWithoutSignal.createConnection === "function") { const oncreate = once((err, socket) => { if (err) { - console.log("emitting error", { err }); this.emit("error", err); } else { this.onSocket(socket); @@ -424,7 +423,6 @@ class ClientRequest extends OutgoingMessage { } _writeHeader() { - console.trace("_writeHeader invoked"); const url = this._createUrlStrFromOptions(); const headers = []; @@ -453,11 +451,8 @@ class ClientRequest extends OutgoingMessage { (async () => { try { const parsedUrl = new URL(url); - console.trace("starting conn"); let baseConnRid = this.socket.rid; - console.log("socket:", baseConnRid); if (this._encrypted) { - console.log("encrypted"); [baseConnRid] = op_tls_start({ rid: this.socket.rid, hostname: parsedUrl.hostname, @@ -467,39 +462,18 @@ class ClientRequest extends OutgoingMessage { } let rid; let connRid; - try { - console.log( - "sending request with conn", - this._bodyWriteRid, - baseConnRid, - this._encrypted, - ); - [rid, connRid] = await op_node_http_request_with_conn( - this.method, - url, - headers, - this._bodyWriteRid, - baseConnRid, - this._encrypted, - ); - } catch (error) { - console.error("error from request with conn", error); - } + [rid, connRid] = await op_node_http_request_with_conn( + this.method, + url, + headers, + this._bodyWriteRid, + baseConnRid, + this._encrypted, + ) + await op_node_http_wait_for_connection(connRid); // Emit request ready to let the request body to be written. - try { - await op_node_http_wait_for_connection(connRid); - } catch (error) { - console.error("error from wait for connection", error); - } - console.log("request ready"); this.emit("requestReady"); - let res; - try { - res = await op_node_http_await_response(rid); - console.log("response received", { res }); - } catch (error) { - console.log("error from await response", error); - } + const res = await op_node_http_await_response(rid); const incoming = new IncomingMessageForClient(this.socket); incoming.req = this; this.res = incoming; @@ -538,43 +512,26 @@ class ClientRequest extends OutgoingMessage { if (this.method === "CONNECT") { throw new Error("not implemented CONNECT"); } - let upgradeRid; - try { - upgradeRid = await op_node_http_fetch_response_upgrade( - res.responseRid, - ); - } catch (error) { - console.log("error from fetch response upgrade", error); - } - assert(typeof res.remoteAddrIp !== "undefined"); - assert(typeof res.remoteAddrIp !== "undefined"); - let conn; - try { - conn = new TcpConn( - upgradeRid, - { - transport: "tcp", - hostname: res.remoteAddrIp, - port: res.remoteAddrIp, - }, - // TODO(bartlomieju): figure out actual values - { - transport: "tcp", - hostname: "127.0.0.1", - port: 80, - }, - ); - } catch (error) { - console.log("error from new connectin"); - } - let socket; - try { - socket = new Socket({ - handle: new TCP(constants.SERVER, conn), - }); - } catch (error) { - console.log("error from new Socket", error); - } + const upgradeRid = await op_node_http_fetch_response_upgrade( + res.responseRid, + ); + const conn = new TcpConn( + upgradeRid, + { + transport: "tcp", + hostname: res.remoteAddrIp, + port: res.remoteAddrIp, + }, + // TODO(bartlomieju): figure out actual values + { + transport: "tcp", + hostname: "127.0.0.1", + port: 80, + }, + ); + const socket = new Socket({ + handle: new TCP(constants.SERVER, conn), + }); this.upgradeOrConnect = true; @@ -604,10 +561,8 @@ class ClientRequest extends OutgoingMessage { // Node.js seems ignoring this error } else if (err.message.includes("The signal has been aborted")) { // Remap this error - console.log("emitting socket hung up error"); this.emit("error", connResetException("socket hang up")); } else { - console.log("emitting error event", err); this.emit("error", err); } } @@ -641,7 +596,6 @@ class ClientRequest extends OutgoingMessage { err = new connResetException("socket hang up"); } if (err) { - console.log("error event", err); emitErrorEvent(req, err); } req._closed = true;