Skip to content

feat: Added --detached option#33

Open
hiikezoe wants to merge 2 commits into
mozilla:masterfrom
hiikezoe:detach
Open

feat: Added --detached option#33
hiikezoe wants to merge 2 commits into
mozilla:masterfrom
hiikezoe:detach

Conversation

@hiikezoe

Copy link
Copy Markdown

Note that closing pipes process leaves caller side to manage the lifetime on
their own.

@hiikezoe hiikezoe force-pushed the detach branch 2 times, most recently from 30cca14 to 8addbd5 Compare March 17, 2018 23:20
@hiikezoe

Copy link
Copy Markdown
Author

@kumar303 r?

Comment thread lib/run.js Outdated
} else {
firefox.stdout.destroy();
firefox.stdin.destroy();
firefox.stderr.destroy();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I still think destroying these streams should be done in caller side, to use this 'detached' option in web-ext, we need facebook/flow#5988 in any way, but it's not clear to me when the PR for flow gets merged. So I've changed to destroy the streams here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiikezoe
I agree with that, and as we briefly discussed over irc, I would really like if we could:

  • be able to keep the child process attached until we are sure that the started Firefox instance is up and running (e.g. in the "web-ext run" use case, we would probably want to wait that we have been able to connect the instance of the chosen remote debugging port) and then unref the child_process from the caller

  • be able to re-attach the stdout and stderr streams related to a detached child process (e.g. looking at the related nodejs docs, https://nodejs.org/api/child_process.html#child_process_options_detached, it seems that we could redirect them to a file or a unix socket file and be able to unref the child_process and exit the parent process' event loop without any need to destroy the streams)

How about this additions to the strategy drafted by this PR:

  • add two additional parameters to the runFirefox function exported by lib/run.js, e.g.: stdoutFilePath, stderrFilePath (or something similar)
  • when the detached options has been specified, set the child_process stdin to 'ignore', and the other two to 'ignore' or to stdoutFilePath and stderrFilePath if they have been specified in the options

how that sounds to you?

(we could also expose these two parameters to the fx-runner bin script, but I'm fine even if we don't expose them from there, I'm not sure that there are so many active users of that bin script)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds pretty reasonable to me. I will make an update PR soon.

Comment thread bin/fx-runner
.then(function(results) {
var firefox = results.process;
if (program.verbose) {
firefox.stdout.pipe(process.stdout)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least with the current implementation, if the 'detached' option has been passed, the firefox.stdout stream has already been destroyed here and so we could probably also skip this firefox.stdout.pipe(process.stdout).

Otherwise, we could destroy the child_process stdio streams at line 41, right before the firefox.unref() call and, when node-fx-runner is used as a library (as in the web-ext CLI tool), the caller is going to decide on its own when it is ready to disconnect the streams and unref the child process.

Comment thread lib/run.js Outdated
} else {
firefox.stdout.destroy();
firefox.stdin.destroy();
firefox.stderr.destroy();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiikezoe
I agree with that, and as we briefly discussed over irc, I would really like if we could:

  • be able to keep the child process attached until we are sure that the started Firefox instance is up and running (e.g. in the "web-ext run" use case, we would probably want to wait that we have been able to connect the instance of the chosen remote debugging port) and then unref the child_process from the caller

  • be able to re-attach the stdout and stderr streams related to a detached child process (e.g. looking at the related nodejs docs, https://nodejs.org/api/child_process.html#child_process_options_detached, it seems that we could redirect them to a file or a unix socket file and be able to unref the child_process and exit the parent process' event loop without any need to destroy the streams)

How about this additions to the strategy drafted by this PR:

  • add two additional parameters to the runFirefox function exported by lib/run.js, e.g.: stdoutFilePath, stderrFilePath (or something similar)
  • when the detached options has been specified, set the child_process stdin to 'ignore', and the other two to 'ignore' or to stdoutFilePath and stderrFilePath if they have been specified in the options

how that sounds to you?

(we could also expose these two parameters to the fx-runner bin script, but I'm fine even if we don't expose them from there, I'm not sure that there are so many active users of that bin script)

@hiikezoe

hiikezoe commented Apr 4, 2018

Copy link
Copy Markdown
Author

Two notes;

  1. getting file descriptors for stdout/stderr looks awkward since it doesn't use await/async
  2. detached and verbose options can no longer coexist
    we can of course make them coexist if we pass 'verbose' option in runFirefox() and set 'pipe' in the case, but it will not be useful since the pipe will close soon.

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.

2 participants