{"record":{"id":"8686d817b30b6859","repo":"apache/flink","slug":"the-thread-was-interrupted-while-waiting-for-a-fet","errorCode":null,"errorMessage":"The thread was interrupted while waiting for a fetcher task.","messagePattern":"The thread was interrupted while waiting for a fetcher task\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcher.java","lineNumber":253,"sourceCode":"                resumed.await();\n                // if it was paused, ensure that fetcher was not shutdown\n                return null;\n            }\n            if (!taskQueue.isEmpty()) {\n                // a specific task is avail, so take that in FIFO\n                return taskQueue.poll();\n            } else if (!assignedSplits.isEmpty()) {\n                // use fallback task = fetch if there is at least one split\n                return fetchTask;\n            } else {\n                // nothing to do, wait for signal\n                nonEmpty.await();\n                return taskQueue.poll();\n            }\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n\n            throw new RuntimeException(\n                    \"The thread was interrupted while waiting for a fetcher task.\");\n        }\n    }\n\n    /**\n     * Add splits to the split fetcher. This operation is asynchronous.\n     *\n     * @param splitsToAdd the splits to add.\n     */\n    public void addSplits(List<SplitT> splitsToAdd) {\n        lock.lock();\n        try {\n            enqueueTaskUnsafe(new AddSplitsTask<>(splitReader, splitsToAdd, assignedSplits));\n            wakeUpUnsafe(true);\n        } finally {\n            lock.unlock();\n        }\n    }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcher.java#L235-L271","documentation":"While waiting for the next task (getNextTaskUnsafe), the SplitFetcher thread's Condition.await was interrupted. The code re-sets the interrupt flag (Thread.currentThread().interrupt()) and throws a RuntimeException. This signals the fetcher is being torn down.","triggerScenarios":"SplitFetcher is shutdown/cancelled while it is idle and blocked on the nonEmpty condition waiting for tasks. Triggered by source close, task cancellation, or failover.","commonSituations":"Job cancellation while the fetcher is idle; source shutdown; failover. Expected during teardown.","solutions":["Treat as expected during cancellation/shutdown; the interrupt flag is preserved so upstream cleanup proceeds.","If observed during steady-state, find what is interrupting the SplitFetcher thread outside the normal close path.","Avoid calling SplitFetcher methods after shutdown to prevent spurious interrupts."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Expected during shutdown; only act if seen outside teardown:\ntry {\n    splitFetcher.run();\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"interrupted while waiting for a fetcher task\")\n            && isShuttingDown) {\n        return; // benign\n    }\n    throw e;\n}","preventionTips":["Do not call addSplits or wakeUp on a SplitFetcher after shutdown().","Let the framework manage fetcher lifecycle; avoid manual thread interruption.","Distinguish teardown interruptions from steady-state failures in error handling."],"tags":["fetcher","interruption","shutdown","flink-source"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}