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

Current use of `opn` prevents graceful shutdown. #196

Open
typhonrt opened this Issue Mar 30, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@typhonrt
Copy link

typhonrt commented Mar 30, 2017

Greets... live-server is great; good work...

I'm embedding live-server into a Node app and there is an issue with opn preventing graceful shutdown. After dealing with unref / destroying sockets to attempt graceful shutdown as noted in #169 there is still an issue with opn. Basically to get live-server to shutdown gracefully wait: false needs to be added to opn invocation. Setting wait to false will resolve the promise in opn immediately including a call to cp.unref(). This separates the browser child process from the calling Node app.

Since I am already wrapping live-server to deal with "unreffing" sockets I simply handle launching the browser / usage of opn directly in my wrapper as necessary always passing open: false to live-server.

It seems reasonable to add optional user input into how opn is invoked. This includes extra options and perhaps also could address #154.

In the short term I don't see any problems with adding wait: false to opn invocation though I haven't run the live-server tests with this change.

Things would change from current to:

if (openPath !== null)
   if (typeof openPath === "object") {
      openPath.forEach(function(p) {
         open(openURL + p, {app: browser, wait: false});
      });
   } else {
      open(openURL + openPath, {app: browser, wait: false});
   }
@typhonrt

This comment has been minimized.

Copy link
Author

typhonrt commented Apr 1, 2017

Just a FYI... If anyone is interested in the wrapper I have created it's on NPM: typhonjs-live-server. It contains the workaround necessary to use live-server and terminate it gracefully when embedded in a Node app in addition to providing a few other utility functions like being able to open the browser at any time. Not that this is important to most, but it also is typhonjs-plugin-manager enabled providing event bindings to control live server. I'll post more documentation soon, but just check out the source code for now: LiveServer.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment