Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin
Created July 22, 2010 04:20
Show Gist options
  • Save ConradIrwin/485563 to your computer and use it in GitHub Desktop.
Save ConradIrwin/485563 to your computer and use it in GitHub Desktop.
diff --git a/lib/net.js b/lib/net.js
index 0bbbdf0..0bd4c7a 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -896,6 +896,10 @@ Stream.prototype.connect = function () {
dns.lookup(arguments[1], function (err, ip, addressType) {
if (err) {
self.emit('error', err);
+ // If the stream is destroyed during the DNS lookup, by an extravagent timeout for example
+ // then continuing is futile.
+ } else if (!self._readWatcher) {
+ self.emit('error', "Stream already destroyed")
} else {
self.type = addressType == 4 ? 'tcp4' : 'tcp6';
self.fd = socket(self.type);
var common = require("../common");
var assert = common.assert
var net = require('net');
var socket = net.createConnection(80, 'localhost');
process.nextTick(function () {
socket.destroy();
});
socket.on('error', function (err) {
assert.equal('Stream already destroyed', err);
});
socket.on('connect', function (err) {
assert.fail();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment