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

Preserving PhantomJS instance across code-reloads in development #1

Open
chriswessels opened this issue Nov 24, 2014 · 2 comments
Open
Assignees

Comments

@chriswessels
Copy link

Hi there,

Thanks for your work on this great smart package.

In my server code I'm running phantomLaunch to start a new instance of PhantomJS and assigning it to a global variable.

Meteor.startup(function () {
  if (typeof PhantomInstance === 'undefined') {
    PhantomInstance = phantomLaunch({ debug: true });
    console.log('Started PhantomJS...');
  }
});

However, upon server reload after a code change, I see this error in the server console:

I20141124-15:17:02.644(0)? Exception in callback of async function: Error: Error: ENOENT, open '/proc/5658/status' [500]
I20141124-15:17:02.647(0)?     at packages/numtel:phantomjs-persistent-server/src/main.js:80
I20141124-15:17:02.647(0)?     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108)

At this time, if I navigate to localhost:13470, I still get output, so PhantomJS is still running. It looks like some vital state information is being lost from reload to reload.

If I just reassign PhantomInstance, the port number increments with each server reload as the old instances of PhantomJS continue to run under Meteor.

Do you know of any acceptable workarounds?

Kind regards,
Chris

@numtel
Copy link
Owner

numtel commented Nov 25, 2014

Thanks for the kind words!

I am not sure I understand how to reproduce this issue. I've copied the posted code into a new meteor 'Hello' app but the orphaned process is detected fine for me. You can see in the following log starting the app and then making a change to the code:

[[[[[ ~/meteor/phantom-issue-1 ]]]]]          

=> Started proxy.                             
=> Started MongoDB.                           
I20141124-19:16:45.300(-8)? PhantomJS server starting on port 13470
I20141124-19:16:45.542(-8)? 13470 Ready.
I20141124-19:16:45.542(-8)? Started PhantomJS...
=> Started your app.

=> App running at: http://localhost:3000/
I20141124-19:18:14.701(-8)? Recovering orphaned port 13470
I20141124-19:18:15.126(-8)? PhantomJS server starting on port 13470
I20141124-19:18:15.142(-8)? 13470 Ready.
I20141124-19:18:15.143(-8)? Started PhantomJS...
=> Meteor server restarted

What OS are you running? If you could post a repo that I could clone to see the error that would be helpful.

As for the auto-port selector, I am considering replacing my linux foo with an NPM package like this: https://www.npmjs.org/package/get-port

From your question though, I wonder if you want the PhantomJS process to continue running after a new code push?

In order to implement this, it would probably be possible to continue issuing requests to an orphaned PhantomJS process but it may be difficult to detect if that process was successfully processing the requests.

Right now, when the code push occurs, your Meteor server (a node.js instance) starts a new process. Because PhantomJS is a child process, it becomes orphaned. This code will kill an orphaned PhantomJS if it occupies the port requested because it assumes that it was originally spawned by the app as well.

-Ben

@numtel numtel self-assigned this Nov 25, 2014
numtel added a commit that referenced this issue Nov 25, 2014
* Intended to fix Mac OSX compatibility
  See: #1
* Also added port property and kill() method to the executive function
@numtel
Copy link
Owner

numtel commented Nov 25, 2014

Ok, I've updated the package with the NPM get-port package. Give 0.0.9 a try!

There are a few changes to the interface:

  • The port option works differently, now a forcePort option is available for automatic code pushes on a static port. Auto selected ports are randomly chosen.
  • The port can be referenced from the executive function, as well as a method for killing the process.

Please let me know if this fixes your issues.

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

No branches or pull requests

2 participants