Skip to content

Conversation

@denyshorman
Copy link
Contributor

@denyshorman denyshorman commented Jan 11, 2026

Summary

This PR fixes a bug where characters were duplicated when using an interactive shell (e.g., "ping" appearing as "ppiinngg"). The fix involves removing the redundant manual echoing logic from TtyFilterOutputStream.

Problem Description

When using InteractiveProcessShellFactory, MINA SSHD starts a local process (like /bin/sh or cmd.exe) and bridges its I/O streams using ProcessShell. ProcessShell used TtyFilterOutputStream to wrap the process's input stream.

TtyFilterOutputStream was configured to manually echo every character received from the client back to the client's output stream if PtyMode.ECHO was enabled (which is common for interactive sessions). However, interactive shells already perform their own echoing. Because ProcessShell operates over pipes rather than a real PTY, both the server-side filter and the shell process were echoing the input, leading to doubled characters.

Standard SSH implementations (like OpenSSH) do not perform manual echoing in the server for shell sessions; they rely on the TTY or the shell process to handle it.

Solution

The manual echoing mechanism in TtyFilterOutputStream has been removed.

  1. PtyMode.ECHO is no longer handled by TtyFilterOutputStream.
  2. The echo parameter (a TtyFilterInputStream) has been removed from TtyFilterOutputStream constructors.
  3. ProcessShell has been updated to stop passing the echo stream.
  4. Added a test ProcessShellTest to verify that input is no longer redundantly echoed to the error stream.

This ensures that only the underlying shell process handles echoing, which is the correct behavior for this type of shell bridging.

Fixes #469.

- Remove redundant manual ECHO handling in TtyFilterOutputStream
- Update ProcessShell to stop passing the echo stream to TtyFilterOutputStream
- Update TtyFilterOutputStream constructors to remove the unused echo parameter
- Update tests to match the new TtyFilterOutputStream API

This fix prevents characters from being duplicated in interactive shell sessions
where the underlying shell process already handles echoing.
@denyshorman denyshorman force-pushed the fix/process-shell-echo-duplication branch from d1ec76f to cdaf9c0 Compare January 11, 2026 18:54
@tomaswolf tomaswolf merged commit 5ee81f4 into apache:master Jan 11, 2026
7 checks passed
@tomaswolf
Copy link
Member

Great job; thank you!

@tomaswolf tomaswolf added this to the 2.17.0 milestone Jan 11, 2026
@denyshorman
Copy link
Contributor Author

Thanks for the quick review!

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.

InteractiveProcessShellFactory . Each character entered is repeated

2 participants