aedes
aedes copied to clipboard
Why is CONNACK returned before the end of on.connect
At my server, on every connection I need to setup some stuff on database before allowing the client to subscribe to channels and start receiving messages:
aedes.on("client", async (client) => {
console.log("ON CLIENT")
console.log("Delaying test for a delayed database task...")
await new Promise(resolve => setTimeout(resolve, 1000));
console.log("Delayed test end...")
console.log("Returning...")
});
The client (using mosquitto) is receiving CONNACK before aedes.on("client") returns...
As doing so, client thinks its all fine with the server and start subscribing channels and sending messages up - and the server is not ready as it's stuck on connect...
Is it the correct behaviour? If so, how can I signal the client that server is ready for processing his requests?
Did you try to use the preConnect
option ?
You could maybe do your DB checks here and call the callback once done ?
@remendes all events listeners doesn't provide any kind of backpressure on the stream, them are simply emitted by the broker and you catch them. Methods that work like you want are preConnect
, authorize
, authorizeSubscribe
, authorizePublish
and published