-
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
Detached processes in deno #5501
Comments
Correct, Deno does not have this functionality yet. I would be happy to add it. Let's figure out what the JS API should look like. We try to not randomly invent new APIs, but instead look at how Node, Go, Rust, Python have exposed it and see if we can use the most common nomenclatures. Would you mind researching this? This would help move the feature forward.
This is the right place for a feature request. |
Firstly Deno has done the right thing by not making detached as default, 'coz that's the default nature of both win API and posix API C has the cleanest way of not having anything in language and having OS specific APIs Node has flat argument structure. while go has Python's subprocess is intended to replace old Rust took the c route of not having anything directly interfaced but left to users via OS specific extension traits ( Largely I can think of two options:
|
How useful is this feature? You can always spawn a separate process by running the script again with different arguments. It would be hard to design security around this. |
Detachment is just one aspect of it. The sub-process creation also has setting uid, gids to the process, which is needed, if we're looking deno as potential replacement for bash and python. And moreover underlying rust is handling it cleanly, so it's a matter of exposing it with a neat interface. |
I would like to comment that on linux children can outlive the parent by default. Here is the test I have been using: |
With a Bash Native Messaging host I can do something like
in the browser so the Native Messaging host does not have to remain open we use
When using a Deno Native Messaging host the Deno server exits when the parent Native Messaging host exists.
I was not expecting that behaviour. Scouring the Manual I was expecting to at least locate a way to keep the child process active if/when the parent process exits. Then I located several issues illuminating the fact this is not currently possible in Deno. Providing users with the option to keep child processes open sounds reasonable to me. |
Deno exits child process when parent process exits denoland/deno#5501
Deno exits child process when parent process exits denoland/deno#5501. Use runtime.connectNative().
@guest271314 if you use the new Command api, I think you can use |
Is that documented anywhere? Which method do the commands get passed to. |
I'll try that out. Thanks. |
This is not working as expected
the process still exits. |
What's the content of |
Note, that is called from a Native Messaging host
Sending the message I need to use
Ideally instead of using a "long-lived" connection to the host from the client I just send a single message (https://developer.chrome.com/docs/extensions/reference/runtime/#method-sendNativeMessage) from the client to the host to turn the server on and off, as I do using Bash https://github.com/guest271314/native-messaging-espeak-ng/tree/master
|
@guest271314 could you boil it down to something easier to reproduce? |
No, not really. You cannot really reproduce a Native Messaging connection using substitute means. Once you create your first Native Messaging host and extension you'll get the hang of it. If you can build Deno you can install a Native Messaging host on Chromium or Chrome. Firefox is a little different. Here are the instructions for each branch. Compare the result for yourself. https://github.com/guest271314/native-messaging-espeak-ng/tree/master. I think you might even be able to substitute the Deno server for If you have any questions don't hesitate to ask. |
I don't even think you have to install or build FWIW This is a generic Deno Native Messaging host that just echos input beginning with an array of 200000 https://github.com/guest271314/native-messaging-deno. |
Try to reproduce this with a child process that just has a We don't need to see communications between the processes to demonstrate whether |
This
does not keep the process created by I always fetch the latest
|
Two videos demonstrating what happens. Both version I use the same "deno_subprocess_exits.webm" shows what happens when we open a process from a parent then the parent exists immediately afterwards. deno_subprocess_exits.webm"deno_subprocess_keep_parent_process_open.webm" shows what happens when we keep the parent process open until the child process, "deno_server.js", serves the response then the client closes the parent process. deno_subprocess_keep_parent_process_open.webm |
That is expected behavior - |
I had no clue about I could could verify Thank you for just saying Deno doesn't support that yet. |
Any updates on this? It seems that using |
Not sure if it helps anyone, but curiously:
Adding explicit Deno.exit() actually worked as a nice workaround for my problem, where I did want to just start a child process on the background and leave it there, while the main program is short lived. Feels like a weird hack, though. (is it actually a bug in Deno.exit(), one would think a script should behave the same when programmatically exited vs naturally come to an end?) I feel like this behaviour is a bit confusing, and it would do good to have all this child process lifetime stuff documented in the Deno.Command docs. Being able to explicitly set child processes as detached or... not detached, would be a nice feature. |
Minimum repro code for this:
However, this is a bug/hack as it does not allow multiple detached processes to run.
will start only one "File Explorer" process on Windows. But if we remove Deno.exit(0); from
then we will fire multiple detached processes. |
Another important usecase the lack of detached ( |
Currently node has the capability to run a child process in detached mode (
setsid()
), which is lacking in deno (?)It seems the Tokio
Command
doesn't expose any specific functionality for this.Is it possible for Deno to provide this functionality?
Also, this specific default (kill if handle is dropped from the scope) in rust std and tokio is overridden in Deno (
cli/ops/process.rs
). Is that related to detached mode?Is there a better place to ask such questions than cluttering the issues section?
The text was updated successfully, but these errors were encountered: