New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: catch writeToStream errors #493
Conversation
Pull Request Test Coverage Report for Build 111168815
|
Pull Request Test Coverage Report for Build 114870214
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a unit test (even with a mock/proxyquire) would be nice.
|
@mcollina I'm // Catch invalid packet writeToStream errors
test('reject client requested for unsupported protocol version', function (t) {
t.plan(3)
const broker = aedes()
t.tearDown(broker.close.bind(broker))
const s = setup(broker)
var packet = [
16, 22, 0, 4, 77, 81, 84, 84,
4, 2, 0, 0, 0, 10, 109, 121,
99, 108, 105, 101, 110, 116, 105, 100,
85, 0
]
s.inStream.write(Buffer.from(packet))
s.outStream.on('data', function (packet) {
t.fail('no data sent')
})
broker.on('connectionError', function (client, err) {
t.equal(client.version, null)
t.equal(err.message, 'Unknown command')
t.equal(broker.connectedClients, 0)
})
})I mean, it works as test but it doesn't make that function throw P.S: I asked to the guy of the email to try this fix and he told me that this has fixed the bug |
|
I mean require the function directly and mock everything. |
|
@mcollina I tried even that way and I'm not able to reproduce the problem, maybe I'm missing something |
|
You should use proxyquire to mock writeToStream. |
|
@mcollina I saw that if there are errors or client is no connecting/connected the write never calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I do not know. |
@mcollina this should fix unhandled expections when a non-valid packet is write to stream