Skip to content
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

Merged
merged 8 commits into from
May 13, 2013

Conversation

rsofaer
Copy link
Contributor

@rsofaer rsofaer commented May 11, 2013

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.

@JeffBezanson
Copy link
Member

Thank you so much for working on this.

@JeffBezanson
Copy link
Member

Do you have any thoughts about #1923?

We are moving away from underscores, and is_open should be isopen.

@rsofaer
Copy link
Contributor Author

rsofaer commented May 11, 2013

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
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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

@vtjnash
Copy link
Member

vtjnash commented May 13, 2013

LGTM. @loladiro ?

@rsofaer
Copy link
Contributor Author

rsofaer commented May 13, 2013

I'm suspicious of that travis build failure. It could be uv_shutdown being
called twice on a stream. Hopefully I'll be able to look at it tonight.

On Mon, May 13, 2013 at 10:12 AM, Jameson Nash [email protected]:

LGTM. @loladiro https://github.com/loladiro ?


Reply to this email directly or view it on GitHubhttps://github.com//pull/3084#issuecomment-17813904
.

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"));
Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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
.

Copy link
Member

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()

@rsofaer
Copy link
Contributor Author

rsofaer commented May 13, 2013

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?

@vtjnash
Copy link
Member

vtjnash commented May 13, 2013

none from me

Keno added a commit that referenced this pull request May 13, 2013
@Keno Keno merged commit 6da4a71 into JuliaLang:master May 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants