add error handlers to requests and sockets

Trying to flush out cause of sporadic socket failures and identify which
socket is not being handled.
This commit is contained in:
Roman Shtylman
2016-11-27 09:49:10 -08:00
parent 5ee2ded1fd
commit 2a6561e774
2 changed files with 19 additions and 10 deletions

View File

@@ -301,6 +301,15 @@ module.exports = function(opt) {
const server = http.createServer(); const server = http.createServer();
server.on('request', function(req, res) { server.on('request', function(req, res) {
req.on('error', (err) => {
console.error('request', err);
});
res.on('error', (err) => {
console.error('response', err);
});
debug('request %s', req.url); debug('request %s', req.url);
if (maybe_bounce(req, res, null, null)) { if (maybe_bounce(req, res, null, null)) {
return; return;
@@ -310,6 +319,14 @@ module.exports = function(opt) {
}); });
server.on('upgrade', function(req, socket, head) { server.on('upgrade', function(req, socket, head) {
req.on('error', (err) => {
console.error('ws req', err);
});
socket.on('error', (err) => {
console.error('ws socket', err);
});
if (maybe_bounce(req, null, socket, head)) { if (maybe_bounce(req, null, socket, head)) {
return; return;
}; };

View File

@@ -28,16 +28,8 @@ test('landing page', function(done) {
var req = http.request(opt, function(res) { var req = http.request(opt, function(res) {
res.setEncoding('utf8'); res.setEncoding('utf8');
var body = ''; assert.equal(res.headers.location, 'https://localtunnel.github.io/www/')
done();
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
assert(body.indexOf('Redirecting to https://localtunnel.github.io/www/') > 0);
done();
});
}); });
req.end(); req.end();