porsager / wright

🚀 Work Fast Work Wright
Do What The F*ck You Want To Public License
180 stars 15 forks source link

Weird behaviour after terminating instance #11

Closed barneycarroll closed 7 years ago

barneycarroll commented 7 years ago

On win32, if I terminate the node instance, the Chrome instance persists. Executing a wright script in another location (from the same shell instance) seemed to lock onto the old instance from the new location, complaining that it couldn't find files pertinent to the previous instance.

After terminating the terminal and the chrome instance, attempting to invoke a wright script again waits for chrome to launch for 30 seconds, finally complaining that it couldn't resolve http://localhost:3001/json/list.

19:41:15.810 Starting wright...
19:41:16.879 Server started on http://localhost:3000
19:41:16.892 Debug: Watching index.html
19:41:16.923 Debug: Watching src/**/*.js
19:41:20.111 Debug: Waiting for chrome to launch
19:41:50.114 Error: Could not connect to http://localhost:3001/json/list

My wright file, which worked in a previous session with no code changes or dependency updates in the interim:

const wright      = require( 'wright' )
const rollup      = require( 'rollup' )
const nodeResolve = require( 'rollup-plugin-node-resolve' )
const commonJs    = require( 'rollup-plugin-commonjs' )

wright( {
  main  : 'index.html',
  debug : true,
  run   : 'm.redraw()',
  js   : {
    watch   : 'src/**/*.js',
    compile : () =>
      rollup.rollup( {
        entry   : 'src/index.js',
        plugins : [ nodeResolve(), commonJs() ]
      } )
      .then( x =>
        x.generate( { format : 'iife' } ).code
      )
  }
} )
barneycarroll commented 7 years ago

This isn't a blocking problem BTW - resolves itself if I reboot.

porsager commented 7 years ago

Could you check if there's a ghost process of chrome running in task manager?

I'll just answer more thoroughly meanwhile ;)

porsager commented 7 years ago

The desired behavior is to not close chrome if the wright process terminates. The reason is that I usually end up opening other tabs in the same window, I'm still not sure it's worth it taking the edge cases reattaching brings into account, but so far it looked possible :)

It should also be possible to run multiple projects at the same time.

There's a specific user-data-dir set for each project depending on the name in config which currently is either a name specified in options or the name of the containing folder.

I wanted to change that by putting a hash of the absolute path on the end of the chrome user-data-dir to resolve name conflicts as there is probably a lot of cases where the containing folder is named "web" or "www".

I imagine it is something like this you bump into together with a stuck chrome instance.. I'll just try it out on windows myself as it might behave a bit differently than on mac.

porsager commented 7 years ago

Unfortunately it seems like an issue with how chrome on windows is reattaching to a running process. With this issue chrome was actually meant to launch two seperate instances, but somehow locks up to the previous one causing it to leave a hanging process that can't be revived (only visible in task manager).

This commit fixes it temporarily on windows but with the downside that chrome will exit when wright exits. (ok as long as you don't have interesting stuff in your app state or something open in other tabs.)