{"record":{"id":"fd2131f30bcf0678","repo":"apache/seatunnel","slug":"transient-mqtt-publish-failure-retrying","errorCode":null,"errorMessage":"Transient MQTT publish failure, retrying...","messagePattern":"Transient MQTT publish failure, retrying\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-mqtt/src/main/java/org/apache/seatunnel/connectors/seatunnel/mqtt/sink/MqttSinkWriter.java","lineNumber":202,"sourceCode":"        }\n        for (MqttMessage message : messageBuffer) {\n            publishWithRetry(message);\n        }\n        messageBuffer.clear();\n    }\n\n    private void publishWithRetry(MqttMessage message) throws IOException {\n        long deadline = System.currentTimeMillis() + retryTimeoutMs;\n        MqttException lastException = null;\n        while (System.currentTimeMillis() < deadline) {\n            try {\n                if (mqttClient.isConnected()) {\n                    mqttClient.publish(topic, message);\n                    return;\n                }\n            } catch (MqttException e) {\n                lastException = e;\n                log.warn(\"Transient MQTT publish failure, retrying...\", e);\n            }\n            try {\n                Thread.sleep(RETRY_BACKOFF_MS);\n            } catch (InterruptedException ie) {\n                Thread.currentThread().interrupt();\n                throw new IOException(\"Interrupted during MQTT publish retry\", ie);\n            }\n        }\n        throw new IOException(\n                new MqttConnectorException(\n                                MqttConnectorErrorCode.PUBLISH_FAILED,\n                                \"Failed to publish MQTT message after \" + retryTimeoutMs + \"ms\")\n                        .getMessage(),\n                lastException);\n    }\n\n    private static MqttConnectOptions buildConnectOptions(ReadonlyConfig config) {\n        MqttConnectOptions options = new MqttConnectOptions();","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-mqtt/src/main/java/org/apache/seatunnel/connectors/seatunnel/mqtt/sink/MqttSinkWriter.java#L184-L220","documentation":"publishWithRetry caught an MqttException during publish while the client reports connected; the error is treated as transient and the method retries after RETRY_BACKOFF_MS. After exhausting retries it throws an IOException carrying lastException, which fails the flush.","triggerScenarios":"mqttClient.publish(topic, message) throws MqttException (transient broker error, QoS timeout) inside publishWithRetry called from flushBuffer.","commonSituations":"Broker under load rejecting publishes, QoS1 timeouts, brief network blips mid-batch, broker hitting max inflight window.","solutions":["Let the built-in retry handle it; if flush ultimately fails, the SeaTunnel framework will retry/restore from checkpoint.","Increase the retry count/backoff options if available in MqttSinkOptions.","Check broker logs for the publish rejection cause.","Reduce flush batch size/frequency to lower inflight pressure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    publishWithRetry(topic, message);\n} catch (IOException e) {\n    // retries exhausted; rely on checkpoint restart or surface the lastException\n    throw new IOException(\"MQTT publish failed after retries\", e.getCause());\n}","preventionTips":["Keep QoS and inflight settings within broker limits","Increase retry count/backoff if the broker is intermittently loaded","Alert on flush failures — they mean retries were exhausted","Check broker logs for publish rejections matching retry storms"],"tags":["mqtt","publish","retry","transient-error"],"backgroundTag":"network-request-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}