Skip to content

Fix SSHHookAsync deadlock on the extra and compress like SSHHook - #76528

Merged
dabla merged 6 commits into
apache:mainfrom
dabla:fix/ssh-hook-async-extra-and-compress
Nov 12, 2026
Merged

dabla merged 6 commits into
apache:mainfrom
dabla:fix/ssh-hook-async-extra-and-compress

Conversation

@dabla

@dabla dabla commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

SSHHookAsync._get_conn parses the connection's extra through conn.extra_dejson. That property masks the extra's secrets with a synchronous call to the supervisor, so in an async task that has another call in flight on the same event loop (for example items run concurrently), opening an SSH connection raises DeadlockImminentError. The hook already fetches the connection with get_async_connection; this reads the extra the same way, with common.compat's get_async_extra_dejson, and hands it to _parse_extras.

The async hook also never set a compression preference, so asyncssh's own default applies, which offers none before zlib@openssh.com. SSHHook compresses by default and lets the compress extra turn it off; SSHHookAsync now does the same, offering zlib@openssh.com, zlib, none (paramiko's order for SSHHook) unless compress is false. The connection docs already describe compress for the SSH connection as a whole. For bulk transfers over SSH this is a measurable difference: on our result files zlib made downloads 5-57% faster, depending on the file.

Notes for reviewers:

  • _parse_extras now takes the extra as a parameter instead of reading conn.extra_dejson itself. It is private, and _get_conn is its only caller in the repository.
  • The common.compat floor stays as it is, with # use next version (get_async_extra_dejson came in 1.21.0).
  • The asyncssh floor moves from 2.12.0 to 2.18.0 (released October 2024), the version whose defaults put none first, so the hook behaves the same on every supported asyncssh version.
  • Behaviour change: connections made by SSHHookAsync, including the SSHRemoteJobTrigger's, now negotiate zlib when the server offers it, as SSHHook connections always have. "compress": "false" in the extra gives uncompressed connections.
  • Because compression_algs is now passed explicitly, asyncssh no longer applies a Compression setting from ~/.ssh/config to these connections; SSHHook never read it either (it takes only ProxyCommand and IdentityFile from that file), so the compress extra is the switch for both hooks. Each compressed connection also holds zlib state (about 0.3 MB) for its lifetime; the connection docs note both under compress, and the SSHRemoteJobOperator page says what it means for a triggerer monitoring many jobs.
  • SFTPHookAsync._parse_extras reads conn.extra_dejson the same way; I left it for a separate PR.

Tests: test_get_conn_reads_extra_asynchronously checks that _get_conn never touches extra_dejson and uses the asynchronously read extra; test_get_conn_compresses_like_sync_hook covers the default and the compress extra as string and boolean. The _parse_extras tests all pass the extra through one helper on a real Connection; the two new tests fail without the change.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Opus 5.5

Generated-by: Claude Opus 5.5 following the guidelines

🤖 Generated with Claude Code

Parsing the connection extra through extra_dejson masks its secrets with
a synchronous supervisor call, which raises DeadlockImminentError when
the hook opens a connection in an async task that has other calls in
flight on the same event loop. The connection itself was already fetched
asynchronously; the extra now is too.

The async hook also left compression to asyncssh, which prefers none,
while SSHHook compresses unless the compress extra is false. Bulk
transfers over the async hook were therefore slower than over the sync
one for no reason.

@Dev-iL Dev-iL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AI has a few nits.

@dabla dabla mentioned this pull request Nov 5, 2026
1 task done
- The asynchronous-extra test builds the connection with an empty extra,
  so it only passes when the extra read through common.compat reaches
  _parse_extras; patches are decorators with autospec on the compat
  helpers (asyncssh.connect stays an AsyncMock, as autospec on an
  @async_context_manager function is not awaitable).
- The _parse_extras tests pass the extra through one helper on a real
  Connection instead of bare MagicMocks; the helper is renamed
  _parse_extra_dict so it no longer shares the method's name.
- The compress check is spelled as in SSHHook.
- The compress docs note that the async hook ignores Compression from
  ~/.ssh/config and that each compressed connection holds zlib state.
@dabla
dabla requested a review from Dev-iL November 5, 2026 09:46

@Dev-iL Dev-iL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for fixing - still approved!

@dabla
dabla requested a review from eladkal November 5, 2026 09:56
Comment thread providers/ssh/docs/connections/ssh.rst Resolved
Comment thread providers/ssh/docs/connections/ssh.rst Resolved
asyncssh offered zlib first by default up to 2.17 and moved "none"
first in 2.18, so the explicit list keeps the same order on every
supported version. Neither hook reads Compression from ~/.ssh/config,
and compress is a connection extra, so the docs point at the connection
SSHRemoteJobOperator uses rather than at the triggerer.
@dabla
dabla requested a review from kaxil November 9, 2026 19:46
Comment thread providers/ssh/docs/connections/ssh.rst Resolved
…perator docs

With asyncssh 2.18 as the floor, SSHHookAsync no longer has to explain what older versions offered by default. The SSH connection docs keep only what holds for the connection; the note about zlib state on a triggerer moves to the SSHRemoteJobOperator page.
@dabla
dabla requested a review from eladkal November 12, 2026 15:01
SSHHookAsync passes its own compression list because asyncssh prefers none from 2.18, the floor. The test fails on an older asyncssh, where zlib came first, so lowering the floor means handling both defaults in the hook.
@dabla
dabla merged commit a67d43f into apache:main Nov 12, 2026
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants