Skip to content

Close SSH channel gracefully on exceptions in port forwarding#885

Merged
tomaswolf merged 3 commits intoapache:masterfrom
tomaswolf:gh-879
Mar 13, 2026
Merged

Close SSH channel gracefully on exceptions in port forwarding#885
tomaswolf merged 3 commits intoapache:masterfrom
tomaswolf:gh-879

Conversation

@tomaswolf
Copy link
Copy Markdown
Member

Fixes #879.

When an exception occurs on the forwarding socket, close the SSH channel
gracefully.
This test was incorrect since the channel windowing was fixed in commit
0c8f9b2 in 2022. It's actually surprising that the test "worked"
somehow for so long, but lately it's been failing more often, in
particular on faster machines.

The basic problem is that since the channel window fix,
AbstcractClientChannel would call LocalWindow.release() when data was
written from the channel to the externally provided OutputStream. This
would then send back a window adjustment to the server, and hence the
server's RemoteWindow would not stay at zero. Apparently the test still
succeeded most of the time (probably because of the very low sleep of
1ms in its busy-waiting loop waiting for the window to drop to zero),
but it may not have tested what it wanted to test.

The solution is to simply not provide an external OutputStream to
the channel. Then the channel sets up its own stream, and calls
LocalWindow.release() only once the data is really read from
invertedOut. That way, the window really drops to zero, and the server
will not get window adjustments.

Despite this seemingly logical fix the test still was flaky. So ignore
it for now.

Note that the test claims to test "full TCP/IP buffers", but it actually
doesn't. It just tests that an idle timeout is effective and can close
the session even when the local window is fully used up.
Using dlcdn.apache.org as URL wasn't a good idea; it carries only the
latest 3.8.x and 3.9.x versions. repo.maven.apache.org keeps all
versions, so use that.
@tomaswolf tomaswolf changed the title Gh 879 Close SSH channel gracefully on exceptions in port forwarding Mar 13, 2026
@tomaswolf tomaswolf merged commit 07cfbba into apache:master Mar 13, 2026
7 checks passed
@tomaswolf tomaswolf deleted the gh-879 branch March 13, 2026 12:16
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.

Local port forwarding not propagating RST packet to server, orphaning the server-side connection

1 participant