question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Terminal resize roundtrip

See original GitHub issue

Issue: Currently resizing the terminal control flow is done like this:

  • terminal.resize triggered by some listener, which listens to grip movements (maybe with fit addon in between) or explicit col/row changes
  • pty gets announced about size change by a sideway comm, this happens async and we dont wait for it to actually happen, basically we dont care when WINCH gets signalled
  • buffers/views are resized (following a specific paradigm like reflow or simple cutting)

Since the pty resize happens async and we dont wait for it to happen there might be data in the buffers from pty to terminal that were written under the old size assumption. This is for most circumstances not a problem, most ASCII input flow scenarios will just work with this, but it might lead to garbage content lines if the slave application relies on the correct terminal size.

Solution: I think this race condition cannot be avoided completely, but narrowed to only a small buffer window by doing the following:

  • terminal.resize gets triggered by some listener
  • terminal sends a XOFF to the pty, thus “halts” any outputting slave program
  • terminal drains all pending data from buffers inserting it with old size
  • terminal announces new size to pty and waits for resize ACK
  • pty signals WINCH
  • on resize ACK:
    • buffers/views are resized
    • XON to reenable data flow

Here the XOFF guarantees that pending data are already written and ACK token ensures that the pty has applied the new size. Have not yet thought about this model in detail, maybe the XOFF full stop could be made less invasive by inserting the ACK token in the websocket stream, maybe the ACK token should even contain the applied size (in case the pty cannot set the requested size for some reason). This size roundtrip certainly would slow down data flow during heavy slave output/terminal input. Furthermore there still might be buffers involved that are not covered by XOFF and contain “wrongly sized” data, mainly on slave app side, like stdout FILE buffer. Not sure how libs like readline deal with buffered data on WINCH or if they always switch off any prebuffering.

Up for discussion, not sure if we should try to mess with this at all, for most scenarios it works good enough as it is now.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jerchcommented, Jan 31, 2019

Made a tracking issue for that: #1918.

Gonna close this issue for now, since we have currently no viable way to control buffer drainage for proper size propagation.

1reaction
Tyriarcommented, Jan 31, 2019

@jerch could be useful for attach, might be best for someone who uses this case to tackle that one as there are downsides to tweaking this (and the best numbers may depend on latency?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can a Terminal window be resized with a Terminal command?
Yes. Terminal supports escape sequences for manipulating windows, including the size and position, layering, and minimizing.
Read more >
XTERM(1) manual page - X.Org
If the underlying operating system supports terminal resizing capabilities ... requiring an extra round trip to the server to find out the previous...
Read more >
Terminal (Lanterna 3.0.4 API)
Adds a TerminalResizeListener to be called when the terminal has changed size. ... but large enough to accommodate a round-trip to the user's...
Read more >
How to set and lock Console size and position? - Stack Overflow
I need help creating an application with a locked window size. I can set the size but not lock it or change the...
Read more >
Query terminal - kitty - Kovid Goyal
This kitten is used to query kitty from terminal programs about version, ... since it requires a roundtrip to the terminal emulator and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found