Skip to content

Fix Pty::resizeWindow: use || instead of &&, and fix swapped assignment - #3718

Open
lijiajun325 wants to merge 2 commits into
kingToolbox:masterfrom
lijiajun325:fix/pty-resize-disconnect
Open

lijiajun325 wants to merge 2 commits into
kingToolbox:masterfrom
lijiajun325:fix/pty-resize-disconnect

Conversation

@lijiajun325

@lijiajun325 lijiajun325 commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary

Fixes two related bugs in src/Pty/ConPty.cpp and src/Pty/WinPty.cpp that together cause SSH sessions to be torn down whenever the WindTerm window is resized or the UI layout is rearranged.

Closes #3717.

Bug Details

Bug 1 - Wrong logical operator (&& should be ||)

ConPty.cpp:204 and WinPty.cpp:170:

if (rows != m_rows && columns != m_columns) {
    // resize ...
}

The condition requires both dimensions to change simultaneously before any resize is sent to the underlying PTY. In practice, resizing by dragging one border only changes one dimension at a time, so the resize is silently dropped and the PTY keeps reporting the old size.

The Unix implementation (UnixPty.cpp:223) already uses ||, which confirms this was the intended logic.

Bug 2 - Reversed assignment

ConPty.cpp:212-213:

if (success) {
    rows = m_rows;          // BUG: writes old member into new parameter
    columns = m_columns;    // BUG: same
}

After a successful resize, the new dimensions are overwritten with the old member values, so the cached dimensions never advance. Combined with bug 1, this means almost every subsequent resize check fails and no further PTY updates are issued until both dimensions happen to change at the exact same moment.

WinPty.cpp:174-175 correctly performs m_rows = rows; m_columns = columns;, so bug 2 only affects the ConPty path.

Reproduction

  1. Open an SSH session in WindTerm 2.7.0.
  2. Drag the window border to resize horizontally only, or rearrange panels / drag tabs.
  3. Observe the SSH session getting disconnected.

Fix

--- a/src/Pty/ConPty.cpp
+++ b/src/Pty/ConPty.cpp
@@ -201,7 +201,7 @@ QByteArray ConPty::readAll() {
 bool ConPty::resizeWindow(qint16 rows, qint16 columns) {
     bool success = true;

-    if (rows != m_rows && columns != m_columns) {
+    if (rows != m_rows || columns != m_columns) {
 #if COMPILE_CONPTY_ENABLED
         HRESULT hr = (m_ptyHandler != INVALID_HANDLE_VALUE)
                    ? ResizePseudoConsole(m_ptyHandler, { columns, rows })
@@ -209,8 +209,8 @@ bool ConPty::resizeWindow(qint16 rows, qint16 columns) {
         success = (hr == S_OK) ? true : false;
 #endif
         if (success) {
-            rows = m_rows;
-            columns = m_columns;
+            m_rows = rows;
+            m_columns = columns;
         }
     }
     Q_ASSERT(success);

--- a/src/Pty/WinPty.cpp
+++ b/src/Pty/WinPty.cpp
@@ -167,7 +167,7 @@ QByteArray WinPty::readAll() {
 bool WinPty::resizeWindow(qint16 rows, qint16 columns) {
     bool success = true;

-    if (rows != m_rows && columns != m_columns) {
+    if (rows != m_rows || columns != m_columns) {
         success = m_ptyHandler ? winpty_set_size(m_ptyHandler, columns, rows, nullptr) : false;

         if (success) {

Verification

A local build of WindTerm with these patches applied was verified to no longer disconnect on:

  • Rapid drag-resizing of the window border.
  • Dragging tabs and splitting panels.
  • Switching DPI / moving the window across monitors.

The local PTY and SSH channel stay in sync as the dimensions change.

Notes

A separate concern, observed during local testing, is that the bundled winpty.dll aborts when called with cols <= 0 || rows <= 0. This seems to happen in the same scenarios (very small intermediate dimensions during layout transitions). That assertion lives inside the Microsoft winpty library and may warrant a separate issue / vendored patch.

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.

SSH connection drops when resizing window or changing layout

1 participant