-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: Defer reading until listeners could be added
Defer reading until user-land has a chance to add listeners. This allows the TLS wrapper to listen for _tlsError and trigger a clientError event if the socket already has data that could trigger. Fixes: #1114 PR-URL: #1496 Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
- Loading branch information
1 parent
7a3006e
commit 061342a
Showing
3 changed files
with
63 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
process.exit(); | ||
} | ||
var tls = require('tls'); | ||
var fs = require('fs'); | ||
var net = require('net'); | ||
|
||
var bonkers = new Buffer(1024); | ||
bonkers.fill(42); | ||
|
||
var receivedError = false; | ||
var options = { | ||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), | ||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') | ||
}; | ||
|
||
var server = net.createServer(function(c) { | ||
setTimeout(function() { | ||
var s = new tls.TLSSocket(c, { | ||
isServer: true, | ||
secureContext: tls.createSecureContext(options) | ||
}); | ||
|
||
s.on('_tlsError', function() { | ||
receivedError = true; | ||
}); | ||
|
||
s.on('close', function() { | ||
server.close(); | ||
s.destroy(); | ||
}); | ||
}, 200); | ||
}).listen(common.PORT, function() { | ||
var c = net.connect({port: common.PORT}, function() { | ||
c.write(bonkers); | ||
}); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.ok(receivedError); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters