-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: uv_shutdown in julia close #3084
Conversation
Thank you so much for working on this. |
Do you have any thoughts about #1923? We are moving away from underscores, and |
I don't really have an opinion on #1923, I think I would need to learn more about how the streams respond to errors etc to help with that. The main thing stream.open is doing here is telling you whether close(stream) has been called. |
function close(stream::AsyncStream) | ||
if stream.open | ||
stream.open = false |
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.
this is a potential race condition?
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.
Should we do something like
if stream.state == OPEN
stream.state = CLOSING
ccall(...)
end
then mark it closed in the callback?
That means resolving #1923
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 my belief that resolving #1923 is the only safe thing to do overall. although it doesn't necessarily need to hold up the pull request since that issue exists independent of this fix
LGTM. @loladiro ? |
I'm suspicious of that travis build failure. It could be uv_shutdown being On Mon, May 13, 2013 at 10:12 AM, Jameson Nash [email protected]:
|
if (handle->type == UV_NAMED_PIPE || handle->type == UV_TCP) { | ||
// Make sure that the stream has not already been marked closed in Julia, which would cause a hang. | ||
// and has not been marked not writable by libuv (eg. by calling uv_shutdown on Windows), which would cause an abort. | ||
jl_function_t* jl_is_open = (jl_function_t*) jl_get_global(jl_base_module, jl_symbol("isopen")); |
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.
This probably should be done one and cached. See the way callbacks work.
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.
right. although it's slightly more annoying than just caching, since during sysimg.jl compile we have two jl_base_module's to look in. using the JULIA_CB macro is probably the way to go 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.
Will I need to modify the JULIA_CB macro to not look for that _uv_hook
string? I don't really feel ready to poke at those macros.
On Mon, May 13, 2013 at 4:25 PM, Jameson Nash [email protected]:
In src/jl_uv.c:
@@ -290,7 +296,26 @@ DLLEXPORT void jl_close_uv(uv_handle_t handle)
return;
if (handle->type==UV_TTY)
uv_tty_set_mode((uv_tty_t)handle,0);
- uv_close(handle,&closeHandle);
- if (handle->type == UV_NAMED_PIPE || handle->type == UV_TCP) {
// Make sure that the stream has not already been marked closed in Julia, which would cause a hang.
// and has not been marked not writable by libuv (eg. by calling uv_shutdown on Windows), which would cause an abort.
jl_function_t\* jl_is_open = (jl_function_t*) jl_get_global(jl_base_module, jl_symbol("isopen"));
right. although it's slightly more annoying than just caching, since
during sysimg.jl compile we have two jl_base_module's to look in. using the
JULIA_CB macro is probably the way to go here—
Reply to this email directly or view it on GitHubhttps://github.com//pull/3084/files#r4201936
.
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.
I was going to suggest fixing it in the other way, by adding a julia method _uv_hook_isopen()
which just dispatches to isopen()
…d closing when a handle isn't writable or closing
I think this is ready to go now. The build is passing, I'm not closing closing streams, and the Julia function is cached. Any new comments? |
none from me |
This pull request resolves issue #2443.
I create a function is_open so that I can find out whether a stream has been marked closed in Julia from the C side, and call it in jl_close_uv to make sure shutdown isn't called twice.
If shutdown is called twice, my test will hang rather than fail. I couldn't figure out how to make that happen well.
I also didn't condense the switch statement in init.c, since I'm not sure whether those separations are still meaningful.
Thanks @vtjnash for helping me a lot with the Julia internals.