-
Notifications
You must be signed in to change notification settings - Fork 235
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
changed net/connect to be non-blocking / asynchronous #1139
Conversation
With a cursory glance, everything looks correct. The intuition about calling
Don't assert, instead panic and clean up as if connect had failed. Generally, we don't assert anything about syscalls and try to convert errno -> janet panic. |
Yes, SIGSEGV later because of a use-after-free, but I wasn't able yet to fully grasp the mechanics involved.
Right, so that would be |
@bakpakin When calling
|
So, on closer inspection the problem seems to be that closing the stream at that point is too early, because later in the loop implementation the stream and it states are still referenced and checked for other events. I guess the right thing to do would be to flag the stream as 'to be closed' (add a stream flag?), and after the last loop iteration close the stream if this flag is set. |
Is there any need to close the stream, or can you just drop it and let the GC take care of it? Might be easier that way - I haven't run with the code yet locally, but elsewhere in the event loop implementation we don't explicitly close anything until the user closes it. |
On second thought, it is probably better to have to close rather than leaving file descriptors open for an undetermined amount of time. |
LGTM, I will run some BSD testing and if that checks out I will merge. |
Yeah, GC-ing file descriptors or sockets is kind of nasty, I agree we better clean them up. |
There is a bug when JANET_NO_EPOLL is defined -> a JanetListenerState is used after being deallocated. Here is a fix:
|
Applied, thanks. Would it make sense to run CI with the |
We already do on sr.ht which is why I don't here, but I guess it would help for contributions. |
This PR makes
net/connect
non-blocking, which I believe is (apart from name resolving) the last change needed to make the Janet network impl all nice and async.I'd appreciate some feedback though:
getsockopt()
failure, panic, assert?