Skip to content

Commit

Permalink
Fix worker crash from bad socket client
Browse files Browse the repository at this point in the history
This bug fixes a problem caused by a socket client quickly disconnecting
after requesting 'data' from a worker socket. I have so far been unable
to track down what has been causing this bad client behavior, but it
seems sensible that a socket client should not be able to crash a worker
like this, so I hope this gets merged.
  • Loading branch information
felixge committed Feb 22, 2012
1 parent b093bfc commit f44d5f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/forever/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Worker.prototype.start = function (callback) {
// with a parent process.
//
function workerProtocol(socket) {
socket.on('error', function() {
socket.destroy();
})

socket.data(['ping'], function () {
socket.send(['pong']);
});
Expand Down
19 changes: 19 additions & 0 deletions test/worker/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ vows.describe('forever/worker/simple').addBatch({
'it should kill the process': function (monitor) {
assert.isFalse(monitor.running);
}
},
'and when quickly sending data and disconnecting': {
topic: function(reader) {
var self = this;

// Need to connect second reader, otherwise it breaks the other
// tests as the reader is shared with them.
var reader2 = new nssocket.NsSocket();
reader2.connect(reader.host, function() {
reader2.send(['data']);
reader2.destroy();

setTimeout(self.callback, 100);
});
},
'it should not crash the worker': function(worker) {
// no asserition, everything is good if the test does not cause
// a worker crash.
}
}
})
}
Expand Down

0 comments on commit f44d5f4

Please sign in to comment.