-
-
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
Changes from 4 commits
59ce04d
fec04d9
aff5834
9c2051b
10cc327
d1207a1
2609de0
4369e52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1000,6 +1000,7 @@ export | |
bind, | ||
connect, | ||
close, | ||
isopen, | ||
countlines, | ||
readcsv, | ||
writecsv, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,12 @@ void closeHandle(uv_handle_t* handle) | |
free(handle); | ||
} | ||
|
||
void shutdownCallback(uv_shutdown_t* req, int status) | ||
{ | ||
uv_close((uv_handle_t*) req->handle,&closeHandle); | ||
free(req); | ||
} | ||
|
||
void jl_return_spawn(uv_process_t *p, int exit_status, int term_signal) | ||
{ | ||
JULIA_CB(return_spawn,p->data,2,CB_INT32,exit_status,CB_INT32,term_signal); | ||
|
@@ -290,7 +296,25 @@ 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 (uv_is_writable((uv_stream_t*)handle) && // uv_shutdown returns an error if not writable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to check the handle type before calling uv_is_writable (just reorder the if statement conditions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the isopen test will need to be swapped with the uv_is_writable test because libuv on windows annoyingly responds to a shutdown request by marking the stream not writable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why swapping the isopen test with the uv_is_writable test would help. It looks like uv_shutdown is doing the same thing on both platforms with regard to writability, if it isn't writable it aborts. We're always going to be able to check both things since we check the handle type first, and if either test fails, going into uv_shutdown is going to cause trouble. Clarify for me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On windows, the is_writable attribute is removed by the call to uv_shutdown, but we don't want to jump to calling uv_close via the else clause if the shutdown call is repeated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I get it, good catch. On Sat, May 11, 2013 at 7:57 PM, Jameson Nash [email protected]:
|
||
(handle->type == UV_NAMED_PIPE || handle->type == UV_TCP)) { | ||
// Make sure that the stream has not already been marked closed in Julia. | ||
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 commentThe 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 commentThe 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 commentThe 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 On Mon, May 13, 2013 at 4:25 PM, Jameson Nash [email protected]:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
if ( jl_apply(jl_is_open, (jl_value_t **) &(handle->data), 1) == jl_false){ | ||
return; | ||
} | ||
|
||
uv_shutdown_t *req = malloc(sizeof(uv_shutdown_t)); | ||
int err = uv_shutdown(req, (uv_stream_t*)handle, &shutdownCallback); | ||
if (err != 0) { | ||
printf("shutdown err: %s\n", uv_strerror(uv_last_error(jl_global_event_loop()))); | ||
uv_close(handle, &closeHandle); | ||
} | ||
} | ||
else{ | ||
uv_close(handle,&closeHandle); | ||
} | ||
} | ||
|
||
DLLEXPORT void jl_uv_associate_julia_struct(uv_handle_t *handle, jl_value_t *data) | ||
|
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
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