{"record":{"id":"85c9a0edf754e91c","repo":"apache/seatunnel","slug":"python-source-was-closed-while-writing-python-scri","errorCode":null,"errorMessage":"Python source was closed while writing python.script.config","messagePattern":"Python source was closed while writing python\\.script\\.config","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-python/src/main/java/org/apache/seatunnel/connectors/seatunnel/python/source/PythonSourceReader.java","lineNumber":351,"sourceCode":"                                initialConfigWritten = true;\n                            }\n                        },\n                        \"python-source-stdin-writer\");\n        stdinWriterThread.setDaemon(true);\n        stdinWriterThread.start();\n    }\n\n    /** Fails process initialization when the child does not consume the initial JSON contract. */\n    private void waitForInitialConfigWrite() throws IOException {\n        try {\n            stdinWriterThread.join(TimeUnit.SECONDS.toMillis(INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS));\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new IOException(\"Interrupted while writing python.script.config\", e);\n        }\n\n        if (closeRequested) {\n            throw new IOException(\"Python source was closed while writing python.script.config\");\n        }\n        if (!initialConfigWritten) {\n            throw new IOException(\n                    \"Timed out after \"\n                            + INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS\n                            + \" seconds while writing python.script.config; ensure the Python script reads its first stdin line\");\n        }\n        if (stdinWriterFailure != null) {\n            if (!process.isAlive()) {\n                // A closed stdin pipe surfaces here as a generic write IOException (e.g. \"Broken\n                // pipe\"), but the actual contract violation is that the script exited without\n                // reading python.script.config; report that instead of the write symptom.\n                throw new IOException(\n                        \"Python script exited before reading its first stdin line;\"\n                                + \" python.script.config could not be delivered\"\n                                + formatRecentStderr(),\n                        stdinWriterFailure);\n            }","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-python/src/main/java/org/apache/seatunnel/connectors/seatunnel/python/source/PythonSourceReader.java#L333-L369","documentation":"The reader tracks whether the initial python.script.config JSON was written to the child's stdin. If close() was requested while that write was still in flight, initialization is aborted with this IOException because the source can no longer be safely started.","triggerScenarios":"Another thread calls close() on the reader (task cancellation, failure of a sibling task, engine shutdown) between open() starting and the stdin writer finishing the initial config write.","commonSituations":"Job cancelled immediately after submission; pipeline failure elsewhere triggers source close during startup; operator stops the Zeta job while the Python process is booting.","solutions":["Rerun/redeploy the job; this indicates a concurrent close, not a script bug","If it fires on every run, check whether upstream failures cancel the task during open()","Avoid submitting jobs that get cancelled immediately (check parallelism, slots, resources)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    reader.open();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"closed while writing\")) {\n        // close was requested concurrently; do not retry within same reader instance\n    }\n}","preventionTips":["Avoid cancelling a job immediately after submission","Investigate sibling-task failures that trigger close during startup"],"tags":["lifecycle","process","shutdown"],"backgroundTag":"invalid-state-transition","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"}