Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

net: fix error handling in listen()

Fixes #1894.
  • Loading branch information...
commit 74cd420529e1d5b5efff54628ff5a18671cbe5f5 1 parent 0b92fa0
Koichi Kobayashi authored

Showing 2 changed files with 45 additions and 6 deletions. Show diff stats Hide diff stats

  1. +6 6 lib/net.js
  2. +39 0 test/simple/test-net-listen-error.js
12 lib/net.js
@@ -643,11 +643,6 @@ var createServerHandle = exports._createServerHandle =
643 643 if (r) {
644 644 handle.close();
645 645 handle = null;
646   -
647   - process.nextTick(function() {
648   - self.emit('error', errnoException(errno, 'listen'));
649   - });
650   - return;
651 646 }
652 647
653 648 return handle;
@@ -662,7 +657,12 @@ Server.prototype._listen2 = function(address, port, addressType) {
662 657 // In the case of a server sent via IPC, we don't need to do this.
663 658 if (!self._handle) {
664 659 self._handle = createServerHandle(address, port, addressType);
665   - if (!self._handle) return;
  660 + if (!self._handle) {
  661 + process.nextTick(function() {
  662 + self.emit('error', errnoException(errno, 'listen'));
  663 + });
  664 + return;
  665 + }
666 666 }
667 667
668 668 self._handle.onconnection = onconnection;
39 test/simple/test-net-listen-error.js
... ... @@ -0,0 +1,39 @@
  1 +// Copyright Joyent, Inc. and other Node contributors.
  2 +//
  3 +// Permission is hereby granted, free of charge, to any person obtaining a
  4 +// copy of this software and associated documentation files (the
  5 +// "Software"), to deal in the Software without restriction, including
  6 +// without limitation the rights to use, copy, modify, merge, publish,
  7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
  8 +// persons to whom the Software is furnished to do so, subject to the
  9 +// following conditions:
  10 +//
  11 +// The above copyright notice and this permission notice shall be included
  12 +// in all copies or substantial portions of the Software.
  13 +//
  14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
  21 +
  22 +var common = require('../common');
  23 +var assert = require('assert');
  24 +var net = require('net');
  25 +var gotError = false;
  26 +
  27 +var server = net.createServer(function(socket) {
  28 +});
  29 +server.listen(1, '1.1.1.1', function() { // EACCESS or EADDRNOTAVAIL
  30 + assert(false);
  31 +});
  32 +server.on('error', function(error) {
  33 + common.debug(error);
  34 + gotError = true;
  35 +});
  36 +
  37 +process.on('exit', function() {
  38 + assert(gotError);
  39 +});

0 comments on commit 74cd420

Please sign in to comment.
Something went wrong with that request. Please try again.