Disable DSUSP (Ctrl+Y) on macOS/BSD to prevent session termination (#29)#143
Open
nix-tkobayashi wants to merge 1 commit into
Open
Disable DSUSP (Ctrl+Y) on macOS/BSD to prevent session termination (#29)#143nix-tkobayashi wants to merge 1 commit into
nix-tkobayashi wants to merge 1 commit into
Conversation
On BSD-derived systems, including macOS, the terminal driver treats Ctrl+Y as the DSUSP (delayed suspend) special character even in cbreak mode. While a shell/SSM session is connected, pressing Ctrl+Y triggers a delayed suspend that makes the Stdin read fail with "read /dev/stdin: resource temporarily unavailable", terminating the session. Linux does not implement DSUSP, so it is unaffected. Disable the DSUSP control character (equivalent to the documented `stty dsusp undef` workaround) on darwin/freebsd/netbsd/openbsd via a new per-OS disableDelayedSuspend(), called from disableEchoAndInputBuffering. It is a no-op on linux, where stty rejects the `dsusp` operand. setState now splits its buffer with strings.Fields so multi-token operands like "dsusp undef" are passed to stty as separate arguments; existing callers pass single tokens and are unaffected. Fixes aws#29 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #29
On BSD-derived systems, including macOS, pressing Ctrl+Y while a shell / SSM
session is connected terminates the session with:
This also affects
aws ecs execute-command --interactive, which uses SessionManager under the hood. Linux and Windows are not affected.
Root cause
disableEchoAndInputBufferingputs the terminal intocbreak -echo, but on BSDterminals the driver still acts on the DSUSP (delayed suspend) special
character, whose default binding is Ctrl+Y. When pressed, the kernel performs a
delayed suspend and the plugin's
Stdinread fails withEAGAIN("resource temporarily unavailable"), which tears down the session.
The documented workaround in #29 is to run
stty dsusp undeflocally beforeconnecting. This PR applies the equivalent setting from within the plugin.
Change
disableDelayedSuspend():shellsession_bsd.go): runsstty dsusp undef.shellsession_linux.go): no-op, because Linux does not implementDSUSP and
sttyrejects thedsuspoperand.disableEchoAndInputBuffering(BSD/macOS only).setStatenow splits its buffer withstrings.Fields, so multi-token operandssuch as
dsusp undefare passed tosttyas separate arguments. Existingcallers pass single tokens (
cbreak,-echo,echo, and thestty -gblob),so their behavior is unchanged.
Windows is untouched (separate
shellsession_windows.go).Testing
go buildfor linux, darwin (amd64/arm64), freebsd, netbsd, openbsd — all pass.go vetandgofmtclean.go test ./src/sessionmanagerplugin/session/shellsession/passes.Licensing
I confirm this contribution is made under the terms of the Apache 2.0 license.