Skip to content

scp: resume non-blocking error cleanup across calls - #2591

Open
Lv2dev wants to merge 3 commits into
libssh2:masterfrom
Lv2dev:codex/scp-error-cleanup
Open

Lv2dev wants to merge 3 commits into
libssh2:masterfrom
Lv2dev:codex/scp-error-cleanup

Conversation

@Lv2dev

@Lv2dev Lv2dev commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

SCP receive and send error cleanup currently keeps retrying libssh2_channel_free() when it returns LIBSSH2_ERROR_EAGAIN, including in non-blocking mode.

Use the existing ssh2_NB_state_error_closing state to return control to the caller and resume cleanup on the next call. Preserve the original error code, message, and ownership flags until cleanup finishes. Release a saved heap-owned message if the session is freed before cleanup completes.

Add a bounded, network-free standalone regression covering receive/send cleanup across calls, restoration of the original error, and saved-message lifetime through completion or session teardown. It uses the common SCP/channel code and does not require a particular crypto backend.

Local validation on upstream bb8e0957 plus this patch:

  • Windows/MSVC/WinCNG: Release and Debug builds with warnings as errors; both standalone tests pass.
  • Linux/Clang/OpenSSL under WSL: project clang-tidy checks and a build with warnings as errors; both standalone tests pass.
  • Linux/Clang/libgcrypt and mbedTLS: builds with warnings as errors; both standalone tests pass on each backend.
  • Linux AddressSanitizer, UndefinedBehaviorSanitizer, and leak detection: both standalone tests pass.
  • Upstream checksrc: passes, including the new test.

Follow-up to #2590 (comment). I have not established whether this explains the original test 621 CI hang. The curl runtime suite is provided by the CI workflow from master; it was not run locally.

@Lv2dev

Lv2dev commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

The remaining OpenSSL CI failure appears to match the previously reported ML-KEM/Ed25519 handshake flake. The build and the new SCP regression pass; one existing read test fails during hostkey signature verification, before authentication.

Could you rerun that job on a75804b6? The other 91 checks passed.

@vszakats vszakats mentioned this pull request Sep 7, 2026
4 tasks done
Comment thread tests/test_scp_nonblock.c

libssh2_exit();
return rc;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this test be compressed into less amount of code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've rebased onto the latest master and simplified the test from 337 to 272 lines in 14ac6580, keeping the four cases and their checks. All 94 CI checks passed. Thanks for the review.

@vszakats

vszakats commented Sep 8, 2026

Copy link
Copy Markdown
Member

The remaining OpenSSL CI failure appears to match the previously reported ML-KEM/Ed25519 handshake flake. The build and the new SCP regression pass; one existing read test fails during hostkey signature verification, before authentication.

Could you rerun that job on a75804b6? The other 91 checks passed.

If you rebase on master, the test will run within this PR.

Lv2dev and others added 3 commits September 9, 2026 13:20
Return control when SCP channel cleanup would block and resume it on the
next call. Preserve the original error and its ownership until cleanup
finishes, including releasing a saved message during session teardown.

Add bounded standalone coverage for receive/send cleanup and saved-error
lifetime without requiring a network or a specific crypto backend.

Co-Authored-By: OpenAI Codex <[email protected]>
Cast each selected enum value to unsigned int so the diagnostic keeps the
correct printf argument type and passes readability-redundant-casting.
This resolves the clang-tidy failures in the SCP cleanup regression test.

Co-Authored-By: OpenAI Codex <[email protected]>
Share cleanup-aware checks and fixture setup, use the existing integer
encoder and default allocator, and report the failed condition and case.
Preserve receive/send EAGAIN counts, original errors, channel cleanup,
and owned-error restoration and teardown checks.
@Lv2dev
Lv2dev force-pushed the codex/scp-error-cleanup branch from a75804b to 14ac658 Compare September 9, 2026 04:30
@Lv2dev

Lv2dev commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Hi, just following up on this PR. Is there anything else you'd like me to adjust before it can move forward? Thanks for your time and review.

@vszakats vszakats left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two small nits to fix while assessing this.

Comment thread tests/test_scp_nonblock.c
return 1;

CHECK(!queue_channel_data(session, ctx.channel, error_payload,
sizeof(error_payload)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
sizeof(error_payload)));
sizeof(error_payload)));

Comment thread tests/test_scp_nonblock.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove headers already included via the first two internal headers.

@vszakats

Copy link
Copy Markdown
Member

Hi, just following up on this PR. Is there anything else you'd like me to adjust before it can move forward? Thanks for your time and review.

I remain unconvinced this will remedy the linked issue. That issue
did not happen again since, so it doesn't look like something to
be fixed at all cost. This PR looks like an LLM-generated one to me,
and I think it would need expert human oversight to move forward.
I personally still find the amount of code too large for what it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants