Gracefully shutting down a Faye.NodeAdapter using the redis engine

68 views
Skip to first unread message

Torgeir Thoresen

unread,
Mar 6, 2012, 2:07:04 PM3/6/12
to faye-...@googlegroups.com
Hey,

What is the preferred way of shutting down a Faye.NodeAdapter that using the redis engine, say from an integration, so that the node process exits?

Without the redis engine, using

var bayeux = new Faye.NodeAdapter({ mount: '/faye' });
...
bayeux.stop();

seems to be working fine, but once I add options for using the redis engine along side the mount option, bayeux.stop() does no longer seem to suffice. It seems as though there are redis connections still hanging open, that prevents node from shutting down. Any ideas?

Best regards,
Torgeir

James Coglan

unread,
Mar 6, 2012, 2:13:29 PM3/6/12
to faye-...@googlegroups.com
On 6 March 2012 19:07, Torgeir Thoresen <torgeir....@gmail.com> wrote:
What is the preferred way of shutting down a Faye.NodeAdapter that using the redis engine, say from an integration, so that the node process exits?

I just use process.exit() if I want to shut down Node. 

Torgeir Thoresen

unread,
Mar 6, 2012, 2:23:56 PM3/6/12
to faye-...@googlegroups.com
Well, if I have other tests running before/after the faye-tests, that's not an option, as it would kill the process. Also, having to kill the program running my tests manually doesn't feel right :) 

From a quick look at the source code, it seems it's trying to shut down the connections cleanly upon calling the stop method, yes?

James Coglan

unread,
Mar 6, 2012, 2:30:09 PM3/6/12
to faye-...@googlegroups.com
On 6 March 2012 19:23, Torgeir Thoresen <torgeir....@gmail.com> wrote:
Well, if I have other tests running before/after the faye-tests, that's not an option, as it would kill the process. Also, having to kill the program running my tests manually doesn't feel right :) 

From a quick look at the source code, it seems it's trying to shut down the connections cleanly upon calling the stop method, yes?

No, it doesn't try to do anything to the engine:


In my experience, libraries leave all sorts of things hanging around that can keep the node process open -- connections, setTimeout calls, etc -- and besides, you need to explicitly exit the process at the end of the tests so you pass a meaningful exit status. 

Torgeir Thoresen

unread,
Mar 6, 2012, 3:10:15 PM3/6/12
to faye-...@googlegroups.com
Oh, I see.

On Tuesday, March 6, 2012 8:30:09 PM UTC+1, James Coglan wrote:

In my experience, libraries leave all sorts of things hanging around that can keep the node process open -- connections, setTimeout calls, etc -- and besides, you need to explicitly exit the process at the end of the tests so you pass a meaningful exit status. 

Well, yes, that's kinda my experience too, but I'd still prefer if they did not..

In this specific case, I'm running some faye tests alongside a series of other tests, with a test framework that would handle the exit status depending on tests passing or failing - but as the process never ends I have no indication of wether or not they are passing.. Also, I have no control over what order the tests are run, so calling process.exit myself is not an option.

Digging around the redis logs, I seem to have two redis connections open after attempting to close the faye nodeadapter. I see the faye-redis-node implement a disconnect https://github.com/faye/faye-redis-node/blob/master/faye-redis.js#L50 Is the way to go?

James Coglan

unread,
Mar 6, 2012, 7:12:23 PM3/6/12
to faye-...@googlegroups.com
On 6 March 2012 20:10, Torgeir Thoresen <torgeir....@gmail.com> wrote:
In this specific case, I'm running some faye tests alongside a series of other tests, with a test framework that would handle the exit status depending on tests passing or failing - but as the process never ends I have no indication of wether or not they are passing.. Also, I have no control over what order the tests are run, so calling process.exit myself is not an option.

I'm not sure what you mean. Shouldn't the test framework exit with the right status for you, or give you a hook to get notified when the tests have finished so you can call exit() yourself?
 
Digging around the redis logs, I seem to have two redis connections open after attempting to close the faye nodeadapter. I see the faye-redis-node implement a disconnect https://github.com/faye/faye-redis-node/blob/master/faye-redis.js#L50 Is the way to go?

It does, but there's no interface on NodeAdapter that calls through to that method. I could add one but I know there will be a ton of other stuff to clean up if you want NodeAdapter.stop() to clean up everything that could keep a Node process running. I don't have time to look at it immediately but feel free to explore and submit a patch. 



--
James Coglan
http://jcoglan.com
+44 (0) 7771512510

Torgeir Thoresen

unread,
Mar 7, 2012, 12:35:12 PM3/7/12
to faye-...@googlegroups.com
On Wednesday, March 7, 2012 1:12:23 AM UTC+1, James Coglan wrote: 
I'm not sure what you mean. Shouldn't the test framework exit with the right status for you, or give you a hook to get notified when the tests have finished so you can call exit() yourself?

Sorry for being unclear, thats what it does - but not when the redis connections don't close.
 
It does, but there's no interface on NodeAdapter that calls through to that method. I could add one but I know there will be a ton of other stuff to clean up if you want NodeAdapter.stop() to clean up everything that could keep a Node process running. I don't have time to look at it immediately but feel free to explore and submit a patch. 

No problem. I don't either at the moment, though I'd love to see/add that some day :)

As a temporary solution for now, the following seems to be working to have node exit after running my tests;

server.once('close', function () {
  bayeux._server._engine.disconnect();
});
Reply all
Reply to author
Forward
0 new messages