Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Airflow SSHOperator stops a long script with SSH command timed out

Errorairflow.exceptions.AirflowException: SSH command timed out

Short answer

SSHOperator waits only 10 seconds for a command by default. A longer script ends the task with SSH command timed out. Set cmd_timeout on the operator (or None for no limit), and set get_pty=True if the remote process must be killed when the task times out.

  • Applies to apache-airflow-providers-ssh (current stable), Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check how long the script really runs on the target host, then compare it with the operator's timeout.

    time python /opt/jobs/report.py
  2. 2Match what you see, then jump to its fix

    1. 1The task fails with SSH command timed out very soon after it starts, even though the script is healthycmd_timeout is still at its 10 second defaultFix
    2. 2The task failed with a timeout, but the process is still in ps on the remote machineThe script keeps running on the host after the task timed outFix
    3. 3Your DAG does not set cmd_timeout, yet the limit differs from the 10 second defaultThe timeout is set in the connection, not in the DAGFix

What does the error look like?

  • airflow.exceptions.AirflowException: SSH command timed out

Cause 1 of 3

cmd_timeout is still at its 10 second default

1Check

In the provider, cmd_timeout defaults to 10 seconds, and a null value means no timeout. See whether your task or the connection extras set it.

grep -rn "cmd_timeout" dags/

2Fix

Set cmd_timeout on the operator to more than the script's real run time. A value of None removes the limit.

from airflow.providers.ssh.operators.ssh import SSHOperator

run_report = SSHOperator(
    task_id="run_report",
    ssh_conn_id="report_host",
    command="python /opt/jobs/report.py",
    cmd_timeout=1800,
)

3Verify

Trigger the task and confirm it stays running past 10 seconds and ends with the script's own exit code.

airflow tasks test my_dag run_report 2026-01-01

Confirmed by airflow.apache.org

Did this fix it?

Cause 2 of 3

The script keeps running on the host after the task timed out

1Check

get_pty defaults to False. Without a pseudo-terminal, the remote process is not killed when the task times out.

ssh deploy@report-host 'ps aux | grep report.py'

2Fix

Set get_pty=True so the remote process is killed on timeout. The provider forces it on anyway when the command starts with sudo.

run_report = SSHOperator(
    task_id="run_report",
    ssh_conn_id="report_host",
    command="python /opt/jobs/report.py",
    cmd_timeout=1800,
    get_pty=True,
)

3Verify

Force a timeout with a small cmd_timeout on a test run and check no report.py process is left.

ssh deploy@report-host 'pgrep -f report.py || echo none'

Confirmed by airflow.apache.org

Did this fix it?

Cause 3 of 3

The timeout is set in the connection, not in the DAG

1Check

The connection page documents cmd_timeout and conn_timeout as Extra fields. conn_timeout is only for the TCP connect, so raising it does not help a long command.

airflow connections get report_host

2Fix

Change cmd_timeout in the connection's Extra JSON, or set it on the operator as above.

{"cmd_timeout": 1800}

3Verify

Run the task again and read the task log for the command output.

airflow tasks test my_dag run_report 2026-01-01

Confirmed by airflow.apache.org

Did this fix it?

How do I stop it coming back?

  • Set cmd_timeout on every SSHOperator that runs more than a few seconds.
  • Use get_pty=True for scripts that must not outlive their task.
  • Make the script idempotent so an Airflow retry after a timeout is safe.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm install fails inside a node:alpine Docker build

Docker Node Alpine Image Build Fails on node-gyp

The node alpine images ship almost nothing beyond Node.js, so a native module that node-gyp must compile has no Python, make or C++ compiler.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.