{"record":{"id":"39c983f3f767fac1","repo":"apache/seatunnel","slug":"thread-interrupted-39c983","errorCode":null,"errorMessage":"Thread interrupted","messagePattern":"Thread interrupted","errorType":"exception","errorClass":"InterruptedException","httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-sqlserver/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/sqlserver/utils/SqlServerUtils.java","lineNumber":183,"sourceCode":"            stmt =\n                    jdbc.connection()\n                            .createStatement(\n                                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);\n\n            stmt.setFetchSize(1024);\n            rs = stmt.executeQuery(sampleQuery);\n\n            int count = 0;\n            while (rs.next()) {\n                count++;\n                if (count % 100000 == 0) {\n                    log.info(\"Processing row index: {}\", count);\n                }\n                if (count % inverseSamplingRate == 0) {\n                    results.add(rs.getObject(1));\n                }\n                if (Thread.currentThread().isInterrupted()) {\n                    throw new InterruptedException(\"Thread interrupted\");\n                }\n            }\n        } finally {\n            if (rs != null) {\n                try {\n                    rs.close();\n                } catch (SQLException e) {\n                    log.error(\"Failed to close ResultSet\", e);\n                }\n            }\n            if (stmt != null) {\n                try {\n                    stmt.close();\n                } catch (SQLException e) {\n                    log.error(\"Failed to close Statement\", e);\n                }\n            }\n        }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-sqlserver/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/sqlserver/utils/SqlServerUtils.java#L165-L201","documentation":"SqlServerUtils.skipReadAndSortSampleData samples split-column values (skipping rows and taking every Nth) and explicitly throws InterruptedException with message 'Thread interrupted' when the current thread's interrupt flag is set mid-iteration. This is cooperative cancellation of the sampling query so the task can stop promptly.","triggerScenarios":"Thread.interrupt() called on the reader thread while the sampling ResultSet loop is iterating — job cancellation by the engine, task restart, or shutdown hook during skipReadAndSortSampleData.","commonSituations":"User cancels or fails the job while the snapshot is sampling data; engine restarts the source reader (e.g. checkpoint/restore); container/pod shutdown; long sampling query on a huge table gets interrupted.","solutions":["Expected during cancellation — no fix needed; the interruption propagates so the task can shut down cleanly","If unexpected, check worker logs for job cancel/restart events just before the error","Reduce sampling cost on very large tables (raise inverse-sampling-rate / split size) so interruption windows are shorter","Ensure the engine's shutdown/restore flow is not spuriously interrupting healthy tasks (check engine version)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check the thread interrupt flag before/inside long sampling loops\nif (Thread.currentThread().isInterrupted()) {\n    throw new InterruptedException(\"Aborting sample before query\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    skipReadAndSortSampleData(...);\n} catch (InterruptedException ie) {\n    Thread.currentThread().interrupt(); // restore flag\n    log.info(\"Sampling cancelled, shutting down reader\");\n    return; // clean exit\n}","preventionTips":["Expect this during job cancellation — treat as normal shutdown","Increase split size / inverse sampling rate to shorten sampling time on huge tables","Avoid stopping containers/workers mid-snapshot; use graceful job stop","Check engine logs for spurious interrupts of healthy tasks"],"tags":["cdc","sqlserver","interrupt","cancellation"],"backgroundTag":"thread-interrupted","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}