Skip to content

Close received after close #1361

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

Closed
vCloudSail opened this issue Nov 23, 2021 · 25 comments
Closed

Close received after close #1361

vCloudSail opened this issue Nov 23, 2021 · 25 comments
Labels

Comments

@vCloudSail
Copy link

vCloudSail commented Nov 23, 2021

Why is this error always reported when running for a long time: WebSocket connection to 'ws://xxx/mqtt' failed: Close received after close
image

version: 4.2.8
browser: Microsoft Edge 95.0.1020.53

@YoDaMa
Copy link
Contributor

YoDaMa commented Dec 24, 2021

Great question. I dunno. Close received after a close suggests that the websocket connection was closed and then subsequently there was a call to close that same websocket connection despite it already being closed. Can you repro it repeatably?

@YoDaMa YoDaMa self-assigned this Dec 24, 2021
@H2pl4U
Copy link

H2pl4U commented Dec 31, 2021

I encountered the same problem, I need to close the socket when reconnecting, but how to configure the code?

@vCloudSail
Copy link
Author

Great question. I dunno. Close received after a close suggests that the websocket connection was closed and then subsequently there was a call to close that same websocket connection despite it already being closed. Can you repro it repeatably?

I can't manually reproduce this situation, which typically occurs multiple times after MQTTJS has been running for a long time

@vCloudSail
Copy link
Author

vCloudSail commented Jan 6, 2022

I encountered the same problem, I need to close the socket when reconnecting, but how to configure the code?

I have changed to the paho.mqtt.js library

@amnonbb
Copy link

amnonbb commented Feb 28, 2022

It's happen when you leave tab inactive for duration more than ~ 1 minutes

@vCloudSail
Copy link
Author

It's happen when you leave tab inactive for duration more than ~ 1 minutes

Do you mean web sleep is the cause?

@amnonbb
Copy link

amnonbb commented Mar 7, 2022

Sorry, din not understand.
Actually yes, looks like it's cause by web sleep.

@YoDaMa
Copy link
Contributor

YoDaMa commented Mar 7, 2022

@amnonbb can you provide a reproducible code snippet please. will attempt repro and debug.

@amnonbb
Copy link

amnonbb commented Mar 10, 2022

I discovered that if i connect with keepalive option = 1 or 2 sec, the error above fire after ~ 5 seconds on inactive tab

@YoDaMa
Copy link
Contributor

YoDaMa commented Mar 10, 2022

@amnonbb and you're just starting a client, connecting via WS, and sending messages? do you have a code snippet i can paste and run?

@amnonbb
Copy link

amnonbb commented Mar 10, 2022

https://mqtt-js.kab.sh

@YoDaMa
Copy link
Contributor

YoDaMa commented Mar 10, 2022

thanks!

@shuiRong
Copy link

same here.

@Zc0412
Copy link

Zc0412 commented Aug 25, 2022

I have the same problem

@jingyuLin1999
Copy link

same here

@jingyuLin1999
Copy link

Has been troubled by this issue. come on!

@wtto00
Copy link

wtto00 commented Jul 11, 2023

When you are listening for a message event, then execute client.end() to close the connection.

If you receive another message during the closing process, it will trigger a Close received after close error.

Change to client.end(true). It will be OK.

@robertsLando
Copy link
Member

MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues

@robertsLando
Copy link
Member

This could be related to #1257 and may be fixed in latest version. Could someone check this?

@amnonbb
Copy link

amnonbb commented Aug 2, 2023

https://mqtt-js.kab.sh

This still alive. Update to v5.0.1

@LiuZiqi-dual
Copy link

This could be related to #1257 and may be fixed in latest version. Could someone check this?

npoe, the problem still exists, it's due to the browser tab throttling, and it's not uncommon for setInterval and setTimeout to lose precision in certain situations (e.g. when a tab is inactive)

The solution I can think of is to create highly accurate timers via Web Wroker (since Web Workers run in a thread separate from the main thread, they are not affected by the main thread and can accurately trigger timer events at any time, even when the main thread's event loop is blocked or the browser tab is inactive).

Of course this comes at the expense of mqtt's compatibility, making it unsupported in Internet Explorer 9 and below.

@Nakus0426
Copy link

Nakus0426 commented Aug 30, 2023

This issue still occurs in version 5.0.3

@robertsLando
Copy link
Member

May be related to #1257

@robertsLando
Copy link
Member

robertsLando commented Dec 4, 2023

May get fixed by #1753 , available starting from version 5.3.2

@binzhou1986
Copy link

When you are listening for a message event, then execute client.end() to close the connection.

If you receive another message during the closing process, it will trigger a Close received after close error.

Change to client.end(true). It will be OK.

great ! MqttClient.prototype.end = function () {...} use end(ture) is very useful

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