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

An error occurs when the MQTT connection is disconnected #5485

Open
LWEN999 opened this issue Dec 29, 2024 · 6 comments
Open

An error occurs when the MQTT connection is disconnected #5485

LWEN999 opened this issue Dec 29, 2024 · 6 comments
Labels
iot Issues related to the IoT SDK pending-maintainer-response Issue is pending response from an Amplify team member question General question

Comments

@LWEN999
Copy link

LWEN999 commented Dec 29, 2024

Describe the bug
After the MQTT connection is established, the listener disconnects and reconnects after a few seconds, and the printed log is
2024-12-29 16:04:44:732 [26786:5024730] WebSocket closed with code:1001 with reason:Stream end encountered
2024-12-29 16:04:44:734 [26786:5024992] MQTT session error, code: 2
2024-12-29 16:04:44:735 [26786:5024992] closing encoder stream.
2024-12-29 16:04:44:735 [26786:5024992] closing decoder stream.

  • SDK Version: 2.38.1
  • Dependency Manager: Cocoapods
  • Xcode Version: 16.1

Device: [iPhone16 pro, Simulator]

  • iOS Version: [ iOS 18.1]
@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Dec 29, 2024
@ruisebas
Copy link
Member

Hi @LWEN999, thanks for reaching out.

Could you please clarify what exactly is the issue or what you want to know?

Reading the code, a WebSocket status with code 1001 is mapped to the NSStreamEventEndEncountered event. The MQTT client will attempt to reconnect because it was not a disconnect request explicitly triggered by the user.

This is expected. If you want to get more information about this situation, you can enable verbose logging by doing the following:

AWSDDLog.sharedInstance.logLevel = .verbose
AWSDDLog.add(AWSDDOSLogger.sharedInstance)

@ruisebas ruisebas added question General question iot Issues related to the IoT SDK labels Dec 30, 2024
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Dec 30, 2024
@ruisebas ruisebas added pending-maintainer-response Issue is pending response from an Amplify team member pending-community-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Dec 30, 2024
@LWEN999
Copy link
Author

LWEN999 commented Dec 31, 2024

Currently, after creating an MQTT connection using the SDK, it is found that there are frequent automatic disconnections and reconnections. What causes this? How do you fix it?

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Dec 31, 2024
@ruisebas
Copy link
Member

As I mentioned, you're getting those reconnections because the app is receiving NSStreamEventEndEncountered.
There might be more information in the verbose logs, so please attach them.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Dec 31, 2024
@LWEN999
Copy link
Author

LWEN999 commented Jan 1, 2025

2025-01-01 14:24:06:488 wuwei-Dev[64510:7677340] WebSocket closed with code:1001 with reason:Stream end encountered
2025-01-01 14:24:06:488 wuwei-Dev[64510:7676954] MQTT session error, code: 2
2025-01-01 14:24:06:489 wuwei-Dev[64510:7676954] closing encoder stream.
2025-01-01 14:24:06:489 wuwei-Dev[64510:7676954] closing decoder stream.
2025 - 01 - 01 14:24:06.489 MQTT connection status:5
2025 - 01 - 01 14:24:06.489 MQTT connection status:5
2025-01-01 14:24:07:493 wuwei-Dev[64510:7677341] Attempting to reconnect.
2025-01-01 14:24:07:494 wuwei-Dev[64510:7677341] AWSIoTMQTTClient: connecting via websocket.
2025-01-01 14:24:07:494 wuwei-Dev[64510:7677341] Using AWSCredentials.
2025-01-01 14:24:07:494 wuwei-Dev[64510:7676954] MQTTSessionEventConnectionClosed: MQTT session closed.
2025 - 01 - 01 14:24:07.495 MQTT connection status:5
2025 - 01 - 01 14:24:07.495 MQTT connection status:5
2025-01-01 14:24:07:495 wuwei-Dev[64510:7677341] user metadata is : ?SDK=iOS&Version=2.38.1
2025-01-01 14:24:07:495 wuwei-Dev[64510:7677341] Metrics collection is: Enabled
2025 - 01 - 01 14:24:07.496 MQTT connection status:1
2025 - 01 - 01 14:24:07.496 MQTT connection status:1
2025-01-01 14:24:08:829 wuwei-Dev[64510:7677341] Websocket did open and is connected.
2025-01-01 14:24:08:831 wuwei-Dev[64510:7677512] <<<AWSIoTStreamThread: 0x6000032dce10>{number = 65, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams
2025-01-01 14:24:08:831 wuwei-Dev[64510:7677512] opening encoder stream.
2025-01-01 14:24:08:831 wuwei-Dev[64510:7677512] opening decoder stream.
2025-01-01 14:24:09:090 wuwei-Dev[64510:7677512] MQTT session connected.
2025-01-01 14:24:09:090 wuwei-Dev[64510:7677512] Auto-resubscribe is enabled. Resubscribing to topics.
2025-01-01 14:24:09:090 wuwei-Dev[64510:7677341] Subscribing to topic granwin/us-east-1:d36aa631-7251-ce3b-0d01-8e710fdbf405/message with ExtendedmessageCallback
2025-01-01 14:24:09:090 wuwei-Dev[64510:7677512] messageId sending now 17
2025-01-01 14:24:09:090 wuwei-Dev[64510:7677341] messageId sending now 18
2025 - 01 - 01 14:24:09.091 MQTT connection status:2
2025 - 01 - 01 14:24:09.091 MQTT connection status:2

Can we find out the cause from the above log?

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 1, 2025
@ruisebas
Copy link
Member

ruisebas commented Jan 2, 2025

Please attach the full logs, i.e. also the entries leading up to "WebSocket closed with code:1001 with reason:Stream end encountered", since that is actually the time period we want to know more about.

On a related note, I've found a SO post with a similar issue that states:

I had a buffer that was sent as soon as my connection opened. If no data was in this buffer, an empty buffer was sent, which is an end signal for the streams

Perhaps this is what's affecting you.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 2, 2025
@ruisebas ruisebas added the pending-community-response Issue is pending response from the issue requestor label Jan 2, 2025
@LWEN999
Copy link
Author

LWEN999 commented Jan 4, 2025

2025-01-04 12:45:46:100 wuwei-Dev[9497:8946842] AWSIoTMQTTClient: connecting via websocket.
2025-01-04 12:45:46:100 wuwei-Dev[9497:8946842] Using AWSCredentials.
2025-01-04 12:45:46:100 wuwei-Dev[9497:8945790] MQTTSessionEventConnectionClosed: MQTT session closed.
2025-01-04 12:45:46:102 wuwei-Dev[9497:8946842] user metadata is : ?SDK=iOS&Version=2.38.1
2025-01-04 12:45:46:102 wuwei-Dev[9497:8946842] Metrics collection is: Enabled
2025-01-04 12:45:47:340 wuwei-Dev[9497:8946940] Websocket did open and is connected.
2025-01-04 12:45:47:340 wuwei-Dev[9497:8946967] <<<AWSIoTStreamThread: 0x60000138c7e0>{number = 53, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams
2025-01-04 12:45:47:340 wuwei-Dev[9497:8946967] opening encoder stream.
2025-01-04 12:45:47:340 wuwei-Dev[9497:8946967] opening decoder stream.
2025-01-04 12:45:47:609 wuwei-Dev[9497:8946967] MQTT session connected.
2025-01-04 12:45:47:609 wuwei-Dev[9497:8946967] Auto-resubscribe is enabled. Resubscribing to topics.
2025 - 01 - 04 12:45:47.610 MQTT connection status:2
2025 - 01 - 04 12:45:47.610 MQTT connection status:2
2025-01-04 12:46:47:856 wuwei-Dev[9497:8948100] WebSocket closed with code:1001 with reason:Stream end encountered
2025-01-04 12:46:47:858 wuwei-Dev[9497:8946967] MQTT session error, code: 2
2025-01-04 12:46:47:859 wuwei-Dev[9497:8946967] closing encoder stream.
2025-01-04 12:46:47:860 wuwei-Dev[9497:8946967] closing decoder stream.
2025 - 01 - 04 12:46:47.860 MQTT connection status:5
2025 - 01 - 04 12:46:47.860 MQTT connection status:5
2025-01-04 12:46:48:863 wuwei-Dev[9497:8948101] Attempting to reconnect.
2025-01-04 12:46:48:863 wuwei-Dev[9497:8948101] AWSIoTMQTTClient: connecting via websocket.
2025-01-04 12:46:48:863 wuwei-Dev[9497:8948101] Using AWSCredentials.
2025-01-04 12:46:48:866 wuwei-Dev[9497:8948101] user metadata is : ?SDK=iOS&Version=2.38.1
2025-01-04 12:46:48:866 wuwei-Dev[9497:8948101] Metrics collection is: Enabled
2025 - 01 - 04 12:46:48.867 MQTT connection status:5
2025-01-04 12:46:48:866 wuwei-Dev[9497:8946967] MQTTSessionEventConnectionClosed: MQTT session closed.
2025 - 01 - 04 12:46:48.867 MQTT connection status:1
2025 - 01 - 04 12:46:48.867 MQTT connection status:5
2025 - 01 - 04 12:46:48.867 MQTT connection status:1
2025-01-04 12:46:50:148 wuwei-Dev[9497:8948100] Websocket did open and is connected.
2025-01-04 12:46:50:148 wuwei-Dev[9497:8948150] <<<AWSIoTStreamThread: 0x600001390510>{number = 58, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams
2025-01-04 12:46:50:148 wuwei-Dev[9497:8948150] opening encoder stream.
2025-01-04 12:46:50:148 wuwei-Dev[9497:8948150] opening decoder stream.
2025-01-04 12:46:50:415 wuwei-Dev[9497:8948150] MQTT session connected.
2025-01-04 12:46:50:416 wuwei-Dev[9497:8948150] Auto-resubscribe is enabled. Resubscribing to topics.
2025 - 01 - 04 12:46:50.416 MQTT connection status:2
2025 - 01 - 04 12:46:50.416 MQTT connection status:2

Currently, only the above logs are printed

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iot Issues related to the IoT SDK pending-maintainer-response Issue is pending response from an Amplify team member question General question
Projects
None yet
Development

No branches or pull requests

2 participants