-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Initial implementation of general user land signal handling (unix only) #2735
Conversation
@@ -36,6 +36,7 @@ pub type OpAsyncFuture<E> = Box<dyn Future<Item = Buf, Error = E> + Send>; | |||
pub enum Op<E> { | |||
Sync(Buf), | |||
Async(OpAsyncFuture<E>), | |||
AsyncOptional(OpAsyncFuture<E>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - what is the purpose of this? I'm not open to adding to this enum...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a marker such that when later registering the op we can tell if the op is optional and should not block event loop exit (by later incrementing optional_ops_count on Isolate
). It is used since I don't think there is some easier way to pass this bit of information down other than with a new enum (otherwise we need to change the signature of Async
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The design of signal is by first calling SignalListen
to add a signal stream to resources. Then signal is actually handled by repeatedly calling SignalPoll
to wait for next poll of signal -- somewhat similar to what we do with TcpStream
read. But unlike reading from TcpStream
, the task registered by SignalPoll
is optional, such that if all other required tasks has finished (pending_ops only contains optional ops), program would exit right away.
@@ -176,6 +176,48 @@ pub fn dispatch_all_legacy( | |||
); | |||
Op::Async(result_fut) | |||
} | |||
Ok(Op::AsyncOptional(fut)) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain? I don't get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually act almost the same as Op::Async
for this part, only that the result wrapping enum is different. I'll see a way if I could avoid duplicate code here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this extra variant?
To make sure the process will exit even when the future is not ready?
I'd suggest to use just Op::Async() and have a separate pending-op count rather than using pending_ops.len()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm misunderstanding, but if both are marked as Op::Async
I don't think Isolate
will be able to tell if a future is optional when polling?
I kind of want to avoid manipulating Isolate
directly from cli (and I'm not quite sure if changing return types of op selectors is a good idea). Also not sure about the counter part since no differentiation between things like enum types mean there is no way I could just decrement for required futures, unless we want to chain another step after the user provided future -- and thus also need to make the counter atomic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need something like uv_unref ... I’m going to punt on this problem until next week - not sure what the right way to handle this is.
My biggest feedback is I am personally not convinced by |
@kitsonk Also That being said, except for that I don't think |
I think we should just stick with the POSIX names to avoid confusion. Most people should not need to ever look at signal stuff. That said, the issue with this patch is rather the lack of |
Closing because this is old. We still don't have a solution to |
Implement general signal handling
sigaction(signo, handler)
.Try it out by pressing Ctrl-C when running this script (wait for TS compiler to finish compile first, since it is not immune to SIGINT):
Notice that signal handler would not block script from exiting after timeout, and multiple handlers could be registered.
Achieved by implementing optional Op type which does not prevent process exit.
Code is hacked up so needs much polishing after confirming the approach. API design feedback also needed.
Tests needed.Added basic unit test