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

Unstable WebSocket connection, recv aio error Object closed #1210

Closed
ElectricEra opened this issue Apr 26, 2023 · 8 comments · Fixed by nanomq/NanoNNG#677
Closed

Unstable WebSocket connection, recv aio error Object closed #1210

ElectricEra opened this issue Apr 26, 2023 · 8 comments · Fixed by nanomq/NanoNNG#677
Assignees
Labels
bug feedback Waiting for futher feedbacks

Comments

@ElectricEra
Copy link

ElectricEra commented Apr 26, 2023

I'm trying to connect to MQTT Broker over WebSocket protocol.
The connection is not established consistently, it results in errors from time to time.

Expected behavior
A connection is established every time.

Actual Behavior
A connection is not established every time.

To Reproduce
Broker setup:
I've used Docker image of NanoMQ broker:
https://hub.docker.com/r/emqx/nanomq
and specified NANOMQ_WEBSOCKET_URL
(docker run -d -p 1883:1883 -p 8883:8883 -p 8083:8083 -e NANOMQ_WEBSOCKET_URL="nmq-ws://0.0.0.0:8083/mqtt" --name nanomq emqx/nanomq:latest)
Latest at the moment is [0.17.3]

Client setup:
For connection setup I've been trying default examples from here (tried both of them, modified mqtt-client-Node.js to connect over WS too). They've resulted in the same outcome.
https://github.com/emqx/MQTT-Client-Examples/tree/master/mqtt-client-React
https://github.com/emqx/MQTT-Client-Examples/tree/master/mqtt-client-Node.js

Connection works the first time, but after first time the client is connected, sometimes connection is not established.

  • Client side:
    The error which is logged during reconnection on client side is undefined
client.on('reconnect', (error) => {
  console.log(`Reconnecting...`, error)
})
Reconnecting... undefined
  • Broker side:
    The error on Docker Container is
WARN  /nanomq/nng/src/sp/transport/mqttws/nmq_websocket.c:126 wstran_pipe_recv_cb:  recv aio error Object closed

Environment Details

Additional context
This issue is irregular. Haven't figured the pattern besides it working the first time a client is trying to connect.
I'm able to "consistently reproduce" it by continuously trying to connect/disconnect to a broker after 1 minute of first connection.

@JaylinYu JaylinYu self-assigned this Apr 27, 2023
@JaylinYu JaylinYu added the Investigation quiestion remains ambiguous label Apr 27, 2023
@JaylinYu
Copy link
Member

JaylinYu commented May 5, 2023

HI ElectricEra,

I have tested the example code and MQTTX (they all base on mqtt.js lib, so they should work in same way), and I fail to reproduce your case. Could you provide more logs regarding this scenario? including the context, the only log you paste here means the TCP connection is actively closed by the client.

@ElectricEra
Copy link
Author

ElectricEra commented May 17, 2023

What I assume is happening - when the Client tries to connect, it establishes a connection to a Broker over WS. Then, if for whatever reason the connection is not disconnected gracefully - it "hangs" (resulting in that error), disabling any other connection from being established. (As described above, I was able to get to this state by trying to rapidly connect/disconnect)

From my client I can see that it sends a "reconnect" message over and over again but with no success. I have to restart a NanoMQ Broker to connect to it again.

I would hope that Broker would "free up" the port and would allow to connect to it again.

Do you think this is the case? If not - feel free to close the issue

@JaylinYu
Copy link
Member

From my client I can see that it sends a "reconnect" message over and over again but with no success. I have to restart a NanoMQ Broker to connect to it again.

This definitely seems weird. Any other logs pops out from nanomq during this? If not this should be more like a network problem.

Or, perhaps the client is using the same socket which has been explicitly closed by broker, then you probably experience such a case that looks like it is a hang (but actually not), because broker doesn't even receive anything!

@JaylinYu
Copy link
Member

Hi @ElectricEra I found a similar issue, it has likely the same symptom as your issue here.
The blocking happens when clients send malformed packets or exceed recv/send quota or any kinds of situation that broker think it is an error. Then broker disconnect this client but never really recover.

If you have time to try it out and give feedback would be appreciate

@ElectricEra
Copy link
Author

Will try, thanks for the updates and fixes!

@yacinehmito
Copy link

I am on version 0.19.5 and seeing something similar.

@JaylinYu
Copy link
Member

We believe our team has successfully resolved this issue #1210 and sincerely apologize for any inconvenience caused. Please verify the fix on the updated master branch, any comment would be appreciated.

@JaylinYu JaylinYu reopened this Aug 28, 2023
@JaylinYu
Copy link
Member

Looking for feedback from @ElectricEra and @yacinehmito

@JaylinYu JaylinYu added bug and removed Investigation quiestion remains ambiguous labels Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feedback Waiting for futher feedbacks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants