apache/seatunnel · error · IOException

Python source was closed while writing python.script.config

Error message

Python source was closed while writing python.script.config

What it means

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.

Source

Thrown at seatunnel-connectors-v2/connector-python/src/main/java/org/apache/seatunnel/connectors/seatunnel/python/source/PythonSourceReader.java:351

                                initialConfigWritten = true;
                            }
                        },
                        "python-source-stdin-writer");
        stdinWriterThread.setDaemon(true);
        stdinWriterThread.start();
    }

    /** Fails process initialization when the child does not consume the initial JSON contract. */
    private void waitForInitialConfigWrite() throws IOException {
        try {
            stdinWriterThread.join(TimeUnit.SECONDS.toMillis(INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IOException("Interrupted while writing python.script.config", e);
        }

        if (closeRequested) {
            throw new IOException("Python source was closed while writing python.script.config");
        }
        if (!initialConfigWritten) {
            throw new IOException(
                    "Timed out after "
                            + INITIAL_CONFIG_WRITE_TIMEOUT_SECONDS
                            + " seconds while writing python.script.config; ensure the Python script reads its first stdin line");
        }
        if (stdinWriterFailure != null) {
            if (!process.isAlive()) {
                // A closed stdin pipe surfaces here as a generic write IOException (e.g. "Broken
                // pipe"), but the actual contract violation is that the script exited without
                // reading python.script.config; report that instead of the write symptom.
                throw new IOException(
                        "Python script exited before reading its first stdin line;"
                                + " python.script.config could not be delivered"
                                + formatRecentStderr(),
                        stdinWriterFailure);
            }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Rerun/redeploy the job; this indicates a concurrent close, not a script bug
  2. If it fires on every run, check whether upstream failures cancel the task during open()
  3. Avoid submitting jobs that get cancelled immediately (check parallelism, slots, resources)
Defensive patterns

Strategy: try-catch

Try / catch

try {
    reader.open();
} catch (IOException e) {
    if (e.getMessage().contains("closed while writing")) {
        // close was requested concurrently; do not retry within same reader instance
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: Job cancelled immediately after submission; pipeline failure elsewhere triggers source close during startup; operator stops the Zeta job while the Python process is booting.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/85c9a0edf754e91c. Report an issue: GitHub.