10000 Impossible to handle server errors like 'EADDRINUSE' without 'domain' · Issue #164 · tj/axon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Impossible to handle server errors like 'EADDRINUSE' without 'domain' #164

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

Open
Skywalker13 opened this issue May 4, 2017 · 0 comments
Open

Comments

@Skywalker13
Copy link
Skywalker13 commented May 4, 2017

Hi,

In sock.js https://github.com/tj/axon/blob/master/lib/sockets/sock.js#L368 , the 'error' event of this.server is not handled then it's not possible to handle the EADDRINUSE error for example (when binding on a non-free port).

I'm doing ugly thing with domain like this:

    this._host = host;
    this._port = parseInt (port);

    /* Create domain in order to catch port binding errors. */
    const domain = require ('domain').create ();

    domain.on ('error', err => {
      this._log.warn (
        'bus binding on %s:%d, error: %s',
        this._host,
        this._port,
        err.message
      );

      if (err.code === 'EADDRINUSE') {
        this._port++;
        this._log.warn (`address in use, retrying on port ${this._port}`);

        setTimeout (() => {
          this._bind (callback);
        }, 0);
        return;
      }

      this._log.err ('this exception is fatal, we cannot continue...');
      process.exit (1);
    });

    /* Try binding in domain. */
    domain.run (() => {
      this._bind (callback);
    });

_bind is using axon.socket (mode).bind ()

The 'error' server event should be exposed by the public API.

Regards

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

1 participant
0