Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Script using Firebase Server won't end. #44

Closed
vjancik opened this issue Apr 22, 2016 · 5 comments
Closed

Script using Firebase Server won't end. #44

vjancik opened this issue Apr 22, 2016 · 5 comments

Comments

@vjancik
Copy link

vjancik commented Apr 22, 2016

I am using the latest version from npm, and running the basic example from docs.

var FirebaseServer = require('firebase-server')
var Firebase = require('firebase')

const instance = new FirebaseServer(5000, 'test.firebaseio.localhost', {
    states: {
        CA: 'California',
        AL: 'Alabama',
        KY: 'Kentucky'
    }
});

var client = new Firebase('ws://test.firebaseio.localhost:5000');
client.once('value', function(snap) {
    console.log('Got value: ', snap.val());
});

I even tried calling instance.close and instance._wss.close() explicitly. But the script still keeps hanging. Do you have some hanging listener left?

Node version v4.4.2 and v5.11.0

@urish
Copy link
Owner

urish commented Apr 24, 2016

Hi, can you try to run the unit tests (git clone this repo, npm install, then npm test) and see if the tests hang for you as well?

@vjancik
Copy link
Author

vjancik commented Apr 24, 2016

Hey, I tried it, they don't. But, I see that you are using Mocha, and another colleague of mine was using Firebase-Server in his tests under Mocha too, and he didn't notice the problem.
This is because Mocha kills the process after running the tests and you need to specify:
--no-exit require a clean shutdown of the event loop: mocha will not call process.exit
to override this behavior. I added the flag to your test script in package.json and it still exited. Apparently, Istanbul kills forcibly as well.
But running ./node_modules/mocha/bin/_mocha --no-exit in the root directory of your package successfully leaves the tests hanging (also doesn't respond to Ctrl+C unless you use bin/mocha, but that's probably a mocha thing).

I hope this helps :)

@urish
Copy link
Owner

urish commented Apr 24, 2016

Yes, this definitely makes sense.

Seems like a problem with the underlaying firebase library:

http://stackoverflow.com/questions/18046639/node-process-doesnt-exit-after-firebase-once
http://stackoverflow.com/questions/27641764/how-to-destroy-firebase-ref-in-node

@shaunburdick
Copy link

One workaround I found when using tape was to call test.onFinish(() => process.exit()); at the end. It's not ideal but it seems to get the job done running it both directly and with a test runner.

Example:

const test = require('tape');

test('Some test', (t) => {
  // test code
});

test('Another test', (t) => {
  // test code
});

test.onFinish(() => process.exit());

@urish
Copy link
Owner

urish commented May 11, 2016

@shaunburdick thanks for sharing your workaround!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants