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

child process stuck in defunct state if uv_close is called before child exited #1911

Open
mchandler-blizzard opened this issue Jul 5, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@mchandler-blizzard
Copy link

commented Jul 5, 2018

After libuv spawned a process using uv_spawn but before the process has exited you call uv_close, libuv will unregister the SIGCHLD handler for that child process and thus never call waitpid when the child exits and cause the child to forever be stuck in the defunct state.

Ether libuv should be updated to internally keep track of this after uv_close has been called or the documentation should be updated to state not to call uv_close until the exit callback has been called.

  • Version: 1.19.1
  • Platform: Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Spawn logic:

      uv_process_options_t options;
      memset(&options, 0, sizeof(uv_process_options_t));

      options.exit_cb = onExit;
      options.file = exe.c_str();
      options.cwd = workingDir.data();
      options.flags = UV_PROCESS_DETACHED;
      options.args = (char**)&argsPtr[0];

      uv_spawn(&loop, m_handle, &options);

      // Need to release the handle to the process due to UV_PROCESS_DETACHED
      uv_unref((uv_handle_t*)m_handle);

Then clean up logic before child has exited that causes it to get stuck:

      uv_close_cb onClose = [](uv_handle_t* handle)	
      {	
        DELETE((uv_process_t*)handle);	
      };	
	
      uv_close((uv_handle_t*)m_handle, onClose);	
      m_handle = nullptr;
@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Jul 6, 2018

That's a documentation issue. Pull request welcome.

@nimit95

This comment has been minimized.

Copy link

commented Aug 20, 2018

I would like to work on this issue

@cjihrig

This comment has been minimized.

Copy link
Contributor

commented Sep 18, 2018

@nimit95 please open a PR if you're still interested in tackling this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.