Skip to content

Commit

Permalink
Issue #8: Fix for case where disconnect/reconnect causes uncaught exc…
Browse files Browse the repository at this point in the history
…eption.
  • Loading branch information
Jason Walton committed Dec 14, 2016
1 parent ae5983f commit efa0d97
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 1 deletion.
12 changes: 12 additions & 0 deletions e2eTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To run these tests, you need a logstash server. You can set one up with:

docker run -it --rm -p 9997:9997 -v "$PWD"/logstash:/logstashcfg logstash -f /logstashcfg/logstash.conf

Then run individual tests and follow the instructions:

node ./disconnectTest.js

If you need to regenerate the certificates for some reason:

openssl req -x509 -newkey rsa:4096 -keyout logstash/key.pem -out logstash/cert.pem \
-days 365 -nodes -subj "/C=CA/ST=Ontario/L=Ottawa/O=Logstash/CN=logstash.local"
41 changes: 41 additions & 0 deletions e2eTest/disconnectTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";

const lumberjack = require('..');
const fs = require('fs');

const connectionOptions = {
host: "localhost",
port: 9997,
ca: [fs.readFileSync('./logstash/cert.pem', {encoding: 'utf-8'})],
rejectUnauthorized: false
};

let state = 0;

let client = lumberjack.client(connectionOptions, {maxQueueSize: 500});

client.on("connect", () => {
client.writeDataFrame({"line": "Connect!"});
if(state === 0) {
state++;
console.log("Connect! Please kill your logstash server.");
} else if(state === 2) {
console.log("Test passed!");
process.exit(0);
} else {
console.log("Test failed - unexpected connect.")
process.exit(1);
}
});
client.on("disconnect", err => {
if(state === 1) {
state++;
console.log("Disconnected. Please restart your logstash server.");
} else if(state === 2) {
// We can get lots of disconnects while we're waiting for the logstash server to restart.
} else {
console.log("Test failed - unexpected disconnect.")
process.exit(1);
}
});
client.on("dropped", count => console.log(`Dropped ${count}`));
35 changes: 35 additions & 0 deletions e2eTest/logstash/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-----BEGIN CERTIFICATE-----
MIIF/TCCA+WgAwIBAgIJAP0SlL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GjgcEwgb4w
HQYDVR0OBBYEFM79eHUKmC8oH4ZpaSKZyQ/6D81jMIGOBgNVHSMEgYYwgYOAFM79
eHUKmC8oH4ZpaSKZyQ/6D81joWCkXjBcMQswCQYDVQQGEwJDQTEQMA4GA1UECBMH
T250YXJpbzEPMA0GA1UEBxMGT3R0YXdhMREwDwYDVQQKEwhMb2dzdGFzaDEXMBUG
A1UEAxMObG9nc3Rhc2gubG9jYWyCCQD9EpSwiBBwKDAMBgNVHRMEBTADAQH/MA0G
CSqGSIb3DQEBBQUAA4ICAQCMbIsqPzJ9fHbUto5XckRrfbhlvDZARSwT7xeq14vd
M9h6t7sYgEr/cUWuqAmHdwdSkSWXMk6R4iOhf9E8vIxj1g/td3FZTxc7jJ+0IjJO
oJtPyZT98o2VYFGTwyxsaFAW++QFBJ/9Arkg7V0R9EupZR6AC6GarznD93oUEKTk
9BYix/qaYW7zLUau12uSA/ze5h1PzJXvRQAJPeqczjNiV0nqEC9qiCyJLwOS4ise
69PyyQL0e35/HuKksIryidiRA22TXU8LSgj2Dx3EMvyVfroTrFpmu2KdUa5rHxVW
UBNYAltWtMfO5mu03HlDhVjJzHGNgeEidtRZ0A5D1CIcwPsyVA6y1z97xxdkx4T9
MoOl44QlF2qrDmj6ne+adaB3HsaNIZZvSygRykWlTGpJw/ir8/7ReLzS4luoTNb9
1bd0mkLeXv5BQ+cD7gH403osNXuOXuhA1kvUjEgI8ppgRzhafd3kLQWBkcBSbKrt
TBbLW9noma/P7alkM0/71aCDr3WJQ5IKStSQCUS02IQruVKiU6MHqtog4IzFBGDV
sKVIi1p7CCew3irago89nq6fG5w0vn7jJ94CdFyqlsg8udd1OUvxymXmM/dLaDXj
j+dMs+zl1lmwfXaylRTnJWMdpqlyOaA74ZLwCvUE4dl7c7Gba6nlle3pjeM9q76v
5A==
-----END CERTIFICATE-----
51 changes: 51 additions & 0 deletions e2eTest/logstash/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-----BEGIN RSA P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: 10 additions & 0 deletions e2eTest/logstash/logstash.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
input {
lumberjack {
port => 9997
ssl_certificate => "/logstashcfg/cert.pem"
ssl_key => "/logstashcfg/key.pem"
}
}
output {
stdout { }
}
4 changes: 3 additions & 1 deletion src/ClientSocket.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ClientSocket extends EventEmitter

@_socket.on 'error', @_disconnect

@_socket.on 'end', => @_disconnect()
@_socket.on 'end', @_disconnect

@_socket.pipe @_parser

Expand All @@ -85,6 +85,8 @@ class ClientSocket extends EventEmitter
@connected = false

@_socket?.removeAllListeners()
# Issue #8: Add a dummy error handler here, so if the socket keeps spewing errors, we'll ignore them.
@_socket.on "error", ->
@_socket = null

# Since we're not going to send any more events...
Expand Down

0 comments on commit efa0d97

Please sign in to comment.