MQTT connection to AWS IoT Core disconnecting and not reconnecting without restarting flows

Could you add something to your flow to check the topics you are posting dont contain any invalid characters?

If possible, add the Bad Topic route (2nd output of function) to a log file or somewhere you can find it historically.

chrome_ESw3yTyB4g

[
    {
        "id": "122dbdbf51b1a76c",
        "type": "function",
        "z": "76a6f1dc1056998c",
        "name": "Check topic",
        "func": "\nvar topicOK = !/[\\+#\\b\\f\\n\\r\\t\\v\\0]/.test(msg.topic);\n\nif(topicOK) {\n    return msg; //first output\n}\nreturn [null, msg]; //second output\n",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1206,
        "y": 864,
        "wires": [
            [
                "7de2b1885ee0ccd0",
                "9ffbfa9abc65a106"
            ],
            [
                "b29d540cf2742c0c"
            ]
        ]
    },
    {
        "id": "3612e50214614a5d",
        "type": "inject",
        "z": "76a6f1dc1056998c",
        "name": "ok topic ",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "test/test3/ok",
        "payloadType": "date",
        "x": 1042,
        "y": 832,
        "wires": [
            [
                "122dbdbf51b1a76c"
            ]
        ]
    },
    {
        "id": "46c1fc418caacb69",
        "type": "inject",
        "z": "76a6f1dc1056998c",
        "name": "bad topic ",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "\"test/test2/test3\\t\"",
                "vt": "json"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 1036,
        "y": 896,
        "wires": [
            [
                "122dbdbf51b1a76c"
            ]
        ]
    },
    {
        "id": "b29d540cf2742c0c",
        "type": "debug",
        "z": "76a6f1dc1056998c",
        "name": "Bad Topic",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "topic",
        "statusType": "msg",
        "x": 1398,
        "y": 896,
        "wires": []
    },
    {
        "id": "7de2b1885ee0ccd0",
        "type": "mqtt out",
        "z": "76a6f1dc1056998c",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "dc811dae.05f5",
        "x": 1378,
        "y": 832,
        "wires": []
    },
    {
        "id": "9ffbfa9abc65a106",
        "type": "debug",
        "z": "76a6f1dc1056998c",
        "name": "OK Topic",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "topic",
        "statusType": "auto",
        "x": 1388,
        "y": 784,
        "wires": []
    },
    {
        "id": "11e6f69902ed534b",
        "type": "inject",
        "z": "76a6f1dc1056998c",
        "name": "ok topic ",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "test/ok",
        "payloadType": "date",
        "x": 1042,
        "y": 784,
        "wires": [
            [
                "122dbdbf51b1a76c"
            ]
        ]
    },
    {
        "id": "8fdd5c87e627832f",
        "type": "inject",
        "z": "76a6f1dc1056998c",
        "name": "bad topic ",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "\"test/test\\n\"",
                "vt": "json"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 1036,
        "y": 944,
        "wires": [
            [
                "122dbdbf51b1a76c"
            ]
        ]
    },
    {
        "id": "dc811dae.05f5",
        "type": "mqtt-broker",
        "name": "",
        "broker": "broker.emqx.io",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "protocolVersion": "5",
        "keepalive": "50",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

I have a suspicion from another issue I am looking into that you might have the odd bad topic going to the broker

See this issue for further details: MQTT nodes do not reconnect if the broker initiates a disconnect · Issue #3367 · node-red/node-red · GitHub

It would be very helpful to let me know if this is what you are observing when the MQTT issue re-occurs.