Skip to content
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

Why is CONNACK returned before the end of on.connect #874

Open
remendes opened this issue Jul 17, 2023 · 2 comments
Open

Why is CONNACK returned before the end of on.connect #874

remendes opened this issue Jul 17, 2023 · 2 comments
Labels

Comments

@remendes
Copy link

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?

@getlarge
Copy link
Member

getlarge commented Sep 7, 2023

Did you try to use the preConnect option ?
You could maybe do your DB checks here and call the callback once done ?

@robertsLando
Copy link
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants