-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π Bug Report β Runtime APIs connect()
and write to an closed port doesn't throw an error
#1305
Comments
Errors should show up in the |
I tried to append const startTime = Date.now()
const socket = connect({ hostname: '1.1.1.1', port: 1234 })
const writer = socket.writable.getWriter()
await writer.write(new TextEncoder().encode("PING\n"))
await socket.close()
await socket.closed
console.log(Date.now() - startTime) It doesn't throw an error and prints I don't think it can finish TCP handshake in less than 1ms, so I guess it haven't completed the handshake when it resolves the promise. |
Also, when I try to run
so I expect |
There was some recent fixes that may help with this, if you can grab workerd HEAD and run your script under that I'd be curious if you can still reproduce this. Be sure to do |
Actually I haven't setup workerd locally and I am now just using Cloudflare Workers. I may try running workerd by myself. and btw I am wondering when the fix will be implemented in Cloudflare? Is there a schedule for that? |
Depends what you mean by "in Cloudflare", it should already be implemented in Cloudflare Workers that are running on our edge. For |
I just tried again on Cloudflare Workers, but the issue seems to remain the same.
The code above returns To verify, you can visit https://worker-noisy-snow-c851.uptimeflare.workers.dev/ So it seems that at least the issue is not fixed now at Cloudflare Workers? |
FWIW, Having the @dom96 ... I haven't looked at it to say for sure but my initial guess is that the error reporting that the connection couldn't be established is not making it's way into the That said, it could be that we're flushing the write (and resolving that promise) before the connection error is returned back up to the |
Ahh, yeah, my bad. @lyc8503 as James mentioned, calling import { connect } from "cloudflare:sockets";
export default {
async fetch(request, env, ctx) {
const startTime = Date.now()
const socket = connect({ hostname: '1.1.1.1', port: 1234 })
const writer = socket.writable.getWriter()
await writer.write(new TextEncoder().encode("PING\n"))
await socket.closed
return new Response(JSON.stringify(Date.now() - startTime))
},
}; And it results in an error as expected. Is this what you were after? If so we can close this issue. |
As for this, let's discuss in the spec repo. I'll make an issue there. |
I'd strongly argue that |
Thanks! This solves the problem for me, so I am closing this issue. BTW its not until now that I've realized actually it's documented here, I was just using it as a "common" socket API but there was something different. π₯ |
Agreed, will get that fixed. |
I am trying to initiate a TCP connection to some
hostname:port
to test if that port is open.In the code above, I open a tcp connection to a closed port
1234
on1.1.1.1
, writes something to that and await for the result. However it doesn't throw any errors.So I assume that when calling
writer.write
it doesn't actually send the data, instead it resolved the promise almost immediately.Now my question is how to determine whether the TCP handshake is done and data is actually sent?
The text was updated successfully, but these errors were encountered: