Server factory integration - #5
Conversation
| The purpose of this module is to be used inside [aedes](https://github.com/moscajs/aedes) `decodeProtocol` hook, which is called when aedes instance receives a first valid buffer from client ( before CONNECT packet). The client object state is in default and its connected state is false. | ||
| The function extract socket details and if aedes `trustProxy` option is set to true, it will first parse http headers (x-real-ip | x-forwarded-for) and proxy protocol (v1 and v2) to retrieve information in client.connDetails. | ||
| The purpose of this module is to be used inside [aedes-server-factory](https://github.com/moscajs/aedes-server-factory) `bindConnection` function, which is called when the server receives a connection from client ( before CONNECT packet). The client object state is in default and its connected state is false. | ||
| The function extract socket details and if aedes-server-factory `trustProxy` option is set to true, it will first parse http headers (x-real-ip | x-forwarded-for) and proxy protocol (v1 and v2) to retrieve information in client.connDetails. |
There was a problem hiding this comment.
| The function extract socket details and if aedes-server-factory `trustProxy` option is set to true, it will first parse http headers (x-real-ip | x-forwarded-for) and proxy protocol (v1 and v2) to retrieve information in client.connDetails. | |
| The function extract socket details and if aedes-server-factory `trustProxy` option is set to true, it will first parse http headers (x-real-ip | x-forwarded-for) and proxy protocol (v1 and v2) to retrieve information in `client.connDetails`. |
|
@getlarge Something like: function setup(options){
var broker;
var server;
var client;
if(options.broker) {
broker = aedes(options.broker)
}
if(options.client) {
client = mqtt.connect(options.client)
}
if(server) {
server = createServer(broker,options.server)
}
return {broker, client, server};
}
function close(setup) {
if(client) client.end(true)
if(broker) broker.close()
if(server) server.close()
}
test('tcp clients have access to the ipAddress from the socket', function (t) {
t.plan(2)
var setup = setup(....)
// code here
t.tearDown(close.bind(t, setup);
}) |
|
@getlarge seems tests are endless on nodejs 12 /14 |
…rge/aedes-protocol-decoder into server-factory-integration
|
@robertsLando yes i noticed, but what i don't understand is that prior to this commit, it was only node v10 which was hanging. |
|
Also i tried to run tests locally with node v12 and this issue does not appear, so i'm kind of stuck with this right now. |
|
@getlarge From my experience with github actions, when weird things happen in tests the best is to disable parallel. LEt's see how this goes :) (already submitted a commit) |
|
@getlarge Seems stucked anyway. It stops here |
|
@mcollina Is there any change in nodejs 10 to 12-14 that could cause this stuck in tests? It stucks in this test: aedes-protocol-decoder/test.js Line 364 in bea03af |
|
The last test in this suite is rather tricky because there are "many" sockets opened, since i tried to reproduce the behavior of a setup with a "real" proxy server. |
|
@getlarge Maybe I got it. I think it could be caused by some leaked handler (open socket). I suggest you to edit your tests in a way that close waits for close callbacks before calling end. function close(setup, t) {
var toClose = 0
var closed = 0
if(client) {
toClose++
client.end(true, onDone)
}
if(broker) {
toClose++
broker.close(onDone)
}
if(server) {
toClose++
server.close(onDone)
}
function onDone() {
if(toClose === ++closed)
t.end()
}
} |
|
I will try. |
|
Also what you could try to do is to create a custom server destroy method as server.close never triggers the callback if there are opened sockets. Or you could you this module: https://github.com/isaacs/server-destroy |
No clue why but if test never ends just means some socket is left opened. So use this strategy and we will for sure find what's wrong here :) |
|
The destroy method did not help, but it seems the error is caused by this block socket.on('end', function (data) {
proxyClient.end(data, function () {
proxyClient.connected = false
})
})When commented the test end properly. |
…rge/aedes-protocol-decoder into server-factory-integration
|
@robertsLando Any idea what that error means at coverall parallel phase ? |
|
No clue but try to re enable parallel, that wasn't the problem |
|
@getlarge lol, a typo :) |
If it's not needed, remove it |
|
Aedes 0.44.0 is on npm |
…rge/aedes-protocol-decoder into server-factory-integration
|
@getlarge Should I release a 2.0.0? |
|
@robertsLando If we strictly follow the semver, then yes you should probably go straight to 2.0.0. |
|
@getlarge Sorry for the delay, published on npm now |
Refactor the protocol decoder
aedes-server-factoryinstead ofaedes)extractSocketDetailsfunction, usable when not using / or trusting proxyUpdate test, docs, examples and dependancies
related to aedes-changes and aedes-server-factory