**Describe the bug**
Cannot get the Retained Messages feature to work correctly with nanomq:0.21.9-full docker image over TLS. Once a message with retain flag is set and published, the same client with the intended topic already subscribed will cause a failure on reconnect. We are using the following tutorial to get the 'Retained Messages' feature to function.

https://nanomq.io/docs/en/latest/tutorial/retain-msg-persistence.html

**Expected behavior**
Supposed to work correctly like with EMQX broker.

**Actual Behavior**
Client is unable to establish connection with the broker if the subscribed topic has a retained message.

**To Reproduce**
We are testing the docker version of nanomq.
 
Clear /tmp content, restart nanomq app and then try to send a retain message to topic A. Subscribe to the topic A with the same client and then try to reconnect. Message should persist. 

**Environment Details**
 - NanoMQ version = 0.21.9-full
 - Operating system and version = Ubuntu 20.04 LTS (ARM 32-bit Allwinner A20 SoC)
 - Testing scenario = Docker Environment

**Additional context**
Below is the log from NanoMQ when the failure occurs.

[nanomq.log](https://github.com/nanomq/nanomq/files/15186243/nanomq.log)

Below is the log from MQTTX client on failure to reconnect :-

```
[2024-05-02 17:20:21] [INFO] Resubscription in progress for topic: test/topic
[2024-05-02 17:20:21] [ERROR] Error subscribing to topic: Error: Connection closed
[2024-05-02 17:20:21] [ERROR] Connection for 192.168.20.101 failed, MQTT.js onError trigger, Error: Error: Invalid variable byte integer
```
Unable to get NanoMQ implementation of Retained Messages to function correctly
This is a GitHub Issue
repo:nanomq
owner:emqx
Title : Unable to get NanoMQ implementation of Retained Messages to function correctly
Issue date:

--- start body ---
**Describe the bug**
Cannot get the Retained Messages feature to work correctly with nanomq:0.21.9-full docker image over TLS. Once a message with retain flag is set and published, the same client with the intended topic already subscribed will cause a failure on reconnect. We are using the following tutorial to get the 'Retained Messages' feature to function.

https://nanomq.io/docs/en/latest/tutorial/retain-msg-persistence.html

**Expected behavior**
Supposed to work correctly like with EMQX broker.

**Actual Behavior**
Client is unable to establish connection with the broker if the subscribed topic has a retained message.

**To Reproduce**
We are testing the docker version of nanomq.
 
Clear /tmp content, restart nanomq app and then try to send a retain message to topic A. Subscribe to the topic A with the same client and then try to reconnect. Message should persist. 

**Environment Details**
 - NanoMQ version = 0.21.9-full
 - Operating system and version = Ubuntu 20.04 LTS (ARM 32-bit Allwinner A20 SoC)
 - Testing scenario = Docker Environment

**Additional context**
Below is the log from NanoMQ when the failure occurs.

[nanomq.log](https://github.com/nanomq/nanomq/files/15186243/nanomq.log)

Below is the log from MQTTX client on failure to reconnect :-

```
[2024-05-02 17:20:21] [INFO] Resubscription in progress for topic: test/topic
[2024-05-02 17:20:21] [ERROR] Error subscribing to topic: Error: Connection closed
[2024-05-02 17:20:21] [ERROR] Connection for 192.168.20.101 failed, MQTT.js onError trigger, Error: Error: Invalid variable byte integer
```
--- end body ---
