{"record":{"id":"af53fe0e50a9d7c1","repo":"apache/seatunnel","slug":"failed-to-flush-data-in-preparecommit-af53fe","errorCode":null,"errorMessage":"Failed to flush data in prepareCommit","messagePattern":"Failed to flush data in prepareCommit","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/sink/HttpSinkWriter.java","lineNumber":170,"sourceCode":"    }\n\n    @Override\n    public void close() throws IOException {\n        if (arrayMode) {\n            flush();\n        }\n        if (Objects.nonNull(httpClient)) {\n            httpClient.close();\n        }\n    }\n\n    @Override\n    public Optional<Void> prepareCommit() {\n        if (arrayMode) {\n            try {\n                flush();\n            } catch (IOException e) {\n                throw new RuntimeException(\"Failed to flush data in prepareCommit\", e);\n            }\n        }\n        return Optional.empty();\n    }\n\n    @VisibleForTesting\n    protected HttpClientProvider createHttpClient(HttpParameter httpParameter) {\n        return new HttpClientProvider(httpParameter);\n    }\n}\n","sourceCodeStart":152,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/sink/HttpSinkWriter.java#L152-L181","documentation":"HttpSinkWriter.prepareCommit flushes buffered rows only in arrayMode; if that flush throws an IOException it is rethrown as RuntimeException 'Failed to flush data in prepareCommit', failing the checkpoint. This ensures batched HTTP writes are committed or the task fails before acknowledgment.","triggerScenarios":"Using the HTTP sink in array mode (array_mode = true) and reaching checkpoint/commit while the target HTTP endpoint returns an error or the request fails (connection refused, timeout, 4xx/5xx).","commonSituations":"Endpoint temporarily down or rate-limiting at commit time, misconfigured URL or auth headers, or payload rejected by the receiving service.","solutions":["Check the cause for the underlying HTTP failure (status code / connection error).","Verify sink URL, headers, and that the endpoint accepts JSON arrays in array mode.","Reduce flush batch size or checkpoint interval to lower commit-time pressure.","Add retry/health handling on the receiving service; restart from the last checkpoint after fixing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check the endpoint accepts the payload\ncurl -s -o /dev/null -w \"%{http_code}\" -X POST \"$URL\" -H \"Content-Type: application/json\" -d '[]' # expect 2xx","typeGuard":null,"tryCatchPattern":"try { writer.prepareCommit(); } catch (RuntimeException e) { Throwable root = ExceptionUtils.getRootCause(e); log.error(\"HTTP sink flush failed: {}\", root.getMessage(), root); throw e; }","preventionTips":["Smoke-test the endpoint URL/headers before the job","Confirm array_mode matches the endpoint's expected payload","Keep checkpoint timeout > worst-case flush duration","Handle 429/5xx on the receiving service"],"tags":["http","sink","checkpoint","flush"],"backgroundTag":"api-request-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}