Skip to content

Commit

Permalink
clean up debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Sep 26, 2024
1 parent be8c90d commit 9c1b39b
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 194 deletions.
2 changes: 0 additions & 2 deletions ext/net/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ impl Resource for TcpStreamResource {
}

fn shutdown(self: Rc<Self>) -> AsyncResult<()> {
eprintln!("shutdown TcpStreamResource");
Box::pin(self.shutdown())
}

fn close(self: Rc<Self>) {
eprintln!("close TcpStreamResource");
self.cancel_read_ops();
}
}
Expand Down
3 changes: 0 additions & 3 deletions ext/net/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ where
let rid = state_
.resource_table
.add(TcpStreamResource::new(tcp_stream.into_split()));
eprintln!("adding TcpStreamResource in op_net_connect_tcp: {rid}");

Ok((rid, IpAddr::from(local_addr), IpAddr::from(remote_addr)))
}
Expand Down Expand Up @@ -655,7 +654,6 @@ pub fn op_set_nodelay_inner(
) -> Result<(), AnyError> {
let resource: Rc<TcpStreamResource> =
state.resource_table.get::<TcpStreamResource>(rid)?;
println!("setting nodelay (rid: {rid}): {nodelay}");
resource.set_nodelay(nodelay)
}

Expand All @@ -676,7 +674,6 @@ pub fn op_set_keepalive_inner(
) -> Result<(), AnyError> {
let resource: Rc<TcpStreamResource> =
state.resource_table.get::<TcpStreamResource>(rid)?;
eprintln!("setting keepalive (rid: {rid}): {keepalive}");
resource.set_keepalive(keepalive)
}

Expand Down
1 change: 0 additions & 1 deletion ext/net/ops_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ where
.borrow::<DefaultTlsOptions>()
.root_cert_store()?;

println!("used in op_tls_start");
let resource_rc = state
.borrow_mut()
.resource_table
Expand Down
1 change: 0 additions & 1 deletion ext/net/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ pub fn take_network_stream_resource(
// The stream we're attempting to unwrap may be in use somewhere else. If that's the case, we cannot proceed
// with the process of unwrapping this connection, so we just return a bad resource error.
// See also: https://github.com/denoland/deno/pull/16242
println!("used in take_network_stream_resource");
if let Ok(resource_rc) = resource_table.take::<TcpStreamResource>(stream_rid)
{
// This TCP connection might be used somewhere else.
Expand Down
26 changes: 2 additions & 24 deletions ext/node/ops/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,8 @@ where
.borrow_mut()
.resource_table
.take::<TcpStreamResource>(conn_rid)?;
eprintln!(
"rc: strong_count: {strong_count} weak_count: {weak_count}",
strong_count = Rc::strong_count(&resource_rc),
weak_count = Rc::weak_count(&resource_rc)
);
let resource = Rc::try_unwrap(resource_rc).map_err(|e| {
eprintln!("error: {:?}", e);
bad_resource("TCP stream is currently in use")
})?;
let resource = Rc::try_unwrap(resource_rc)
.map_err(|e| bad_resource("TCP stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let tcp_stream = read_half.reunite(write_half)?;
let io = TokioIo::new(tcp_stream);
Expand All @@ -128,11 +121,9 @@ where

// Spawn a task to poll the connection, driving the HTTP state
let _handle = tokio::task::spawn(async move {
eprintln!("rs: connection started");
conn_start.store(true, std::sync::atomic::Ordering::Relaxed);
let _ = notify.send(());
conn.await?;
eprintln!("rs: connection completed");
Ok::<_, AnyError>(())
});

Expand Down Expand Up @@ -199,9 +190,6 @@ where
request.headers_mut().insert(CONTENT_LENGTH, len.into());
}

eprintln!("rs: sending request: {request:?}");
// let req_fut = sender.send_request(request);
// let res = tokio::time::timeout(Duration::from_secs(10), req_fut).await??;
let res = sender.send_request(request).map_err(Error::from).boxed();
let rid = state
.borrow_mut()
Expand Down Expand Up @@ -248,15 +236,7 @@ pub async fn op_node_http_await_response(
let resource = Rc::try_unwrap(resource)
.map_err(|_| bad_resource("NodeHttpClientResponse"))?;

eprintln!(
"rs: awaiting response: {}",
resource
.connection_started
.load(std::sync::atomic::Ordering::Relaxed)
);
let res = resource.response.await?;
// let res = tokio::time::timeout(Duration::from_secs(10), req_fut).await??;
eprintln!("rs: received response");

let status = res.status();
let mut res_headers = Vec::new();
Expand All @@ -280,7 +260,6 @@ pub async fn op_node_http_await_response(
let body = body.boxed();

let res = http::Response::from_parts(parts, body);
println!("res: {res:?}");

let response_rid = state
.borrow_mut()
Expand Down Expand Up @@ -556,7 +535,6 @@ impl Stream for NodeHttpResourceToBodyAdapter {
Poll::Ready(res) => match res {
Ok(buf) if buf.is_empty() => Poll::Ready(None),
Ok(buf) => {
println!("rs: reading: {len}", len = buf.len());
this.1 = Some(this.0.clone().read(64 * 1024));
Poll::Ready(Some(Ok(buf.to_vec().into())))
}
Expand Down
1 change: 0 additions & 1 deletion ext/node/polyfills/_http_agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
});

const newSocket = this.createConnection(options, oncreate);
console.log("agent: creating a connection", newSocket._handle.rid);
if (newSocket) {
oncreate(null, newSocket);
}
Expand Down
38 changes: 1 addition & 37 deletions ext/node/polyfills/_http_outgoing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,9 @@ Object.defineProperties(
const outputLength = this.outputData.length;
if (socket && outputLength > 0) {
const { data, encoding, callback } = this.outputData.shift();
console.log("flushBody: writing", { data });
this._writeRaw(data, encoding, callback);
if (this.outputData.length > 0) {
this.on("drain", () => {
console.log("drain emitted");
this._flushBody();
});
}
Expand All @@ -512,19 +510,13 @@ Object.defineProperties(
/** Right after socket is ready, we need to writeHeader() to setup the request and
* client. This is invoked by onSocket(). */
_flushHeaders() {
console.log("flushHeaders");
if (this.socket) {
console.log("socket found: ", {
headerSent: this._headerSent,
header: this._header,
});
if (!this._headerSent) {
console.log("_writeHeader invoked");
this._writeHeader();
this._headerSent = true;
}
} else {
console.log("socket not found");
console.warn("socket not found");
}
},

Expand All @@ -533,32 +525,15 @@ Object.defineProperties(
// 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("_send(): im never invoked");
if (!this._headerSent && this._header !== null) {
this._writeHeader();
this._headerSent = true;
}

if (this._headerSent) {
console.log("_send(): writeRaw", data, encoding, callback);
return this._writeRaw(data, encoding, callback);
}
} else {
// if (!this._listenerSet) {
// this._listenerSet = true;
// this.on("socket", (socket) => {
// console.log("socket rid:", socket._handle.rid);
// socket.on("ready", () => {
// if (!this._headerSent && this._header !== null) {
// this._writeHeader();
// this._headerSent = true;
// }

// this._flushBuffer();
// });
// });
// }
console.log("_send(): pushing to outputData:", this.outputData.length);
this.outputData.push({ data, encoding, callback });
}
},
Expand Down Expand Up @@ -591,7 +566,6 @@ Object.defineProperties(
}).catch((e) => {
this._requestSendError = e;
});
console.log("flushing data:", data, ret);
}

this.outputData = [];
Expand All @@ -606,28 +580,18 @@ Object.defineProperties(
encoding?: string | null,
callback?: () => void,
) {
console.trace("_writeRaw invoked:", data.length);
if (typeof data === "string") {
data = Buffer.from(data, encoding);
}
if (data instanceof Buffer) {
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (data.buffer.byteLength > 0) {
console.log(
"writing to",
this._bodyWriteRid,
"desired size",
this._bodyWriter.desiredSize,
"writer",
this._bodyWriter,
);
this._bodyWriter.ready.then(() => {
if (this._bodyWriter.desiredSize > 0) {
this._bodyWriter.write(data).then(() => {
callback?.();
if (this.outputData.length == 0) {
console.log("emitting finish for", { data });
this.emit("finish");
}
this.emit("drain");
Expand Down
Loading

0 comments on commit 9c1b39b

Please sign in to comment.