{"record":{"id":"f202738829dfc4dd","repo":"apache/seatunnel","slug":"failed-to-close-connection","errorCode":null,"errorMessage":"Failed to close connection","messagePattern":"Failed to close connection","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/reader/fetch/MySqlSourceFetchTaskContext.java","lineNumber":201,"sourceCode":"                        new MySqlStreamingChangeEventSourceMetrics(\n                                taskContext, queue, metadataProvider));\n        this.snapshotChangeEventSourceMetrics =\n                changeEventSourceMetricsFactory.getSnapshotMetrics(\n                        taskContext, queue, metadataProvider);\n        this.streamingChangeEventSourceMetrics =\n                (MySqlStreamingChangeEventSourceMetrics)\n                        changeEventSourceMetricsFactory.getStreamingMetrics(\n                                taskContext, queue, metadataProvider);\n        this.errorHandler = new MySqlErrorHandler(connectorConfig, queue);\n    }\n\n    @Override\n    public void close() {\n        try {\n            this.connection.close();\n            this.binaryLogClient.disconnect();\n        } catch (SQLException e) {\n            log.warn(\"Failed to close connection\", e);\n        } catch (IOException e) {\n            log.warn(\"Failed to close binaryLogClient\", e);\n        }\n    }\n\n    @Override\n    public MySqlSourceConfig getSourceConfig() {\n        return (MySqlSourceConfig) sourceConfig;\n    }\n\n    public MySqlConnection getConnection() {\n        return connection;\n    }\n\n    public BinaryLogClient getBinaryLogClient() {\n        return binaryLogClient;\n    }\n","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/reader/fetch/MySqlSourceFetchTaskContext.java#L183-L219","documentation":"MySqlSourceFetchTaskContext.close() closes the JDBC connection and disconnects the binary-log client. If connection.close() throws a SQLException, this warning is logged with the exception while the binaryLogClient disconnect is skipped, because both calls share a single try block.","triggerScenarios":"close() is called during reader/task teardown; this.connection.close() throws SQLException (connection already closed, socket broken, driver error) and the warning is logged before binaryLogClient.disconnect() can run.","commonSituations":"Task shutdown after a MySQL server restart or network drop (connection already dead); double-close when the reader is cancelled and then closed; long-running incremental read where the connection timed out before close.","solutions":["If seen during normal shutdown, it is harmless — the connection was already dead; verify the task completed otherwise.","Reorder/fix code so each resource is closed independently (try-with-resources or separate try blocks) so the binaryLogClient still gets disconnected.","Check MySQL server logs and network stability (wait_timeout, max_allowed errors) if it appears frequently.","Upgrade the connector/driver version if double-close races are involved."],"exampleFix":"// before\ntry {\n    this.connection.close();\n    this.binaryLogClient.disconnect();\n} catch (SQLException e) { log.warn(\"Failed to close connection\", e); }\n// after\ntry { this.connection.close(); } catch (SQLException e) { log.warn(\"Failed to close connection\", e); }\ntry { this.binaryLogClient.disconnect(); } catch (IOException e) { log.warn(\"Failed to close binaryLogClient\", e); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try (Connection c = dataSource.getConnection()) {\n    // work\n} // auto-close handles already-closed connections safely","preventionTips":["Close the JDBC connection and BinaryLogClient in independent try/catch blocks","Treat close-time SQLException during shutdown as benign; focus on the original failure","Tune wait_timeout/keepalives for long incremental reads","Avoid double-close paths (cancel followed by close)"],"tags":["mysql","jdbc","resource-cleanup","shutdown"],"backgroundTag":"broken-pipe","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"}