Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use os.Stderr instead of os.Stdout with fmt.Fprintf() #20

Open
wants to merge 1 commit into
base: mainline
Choose a base branch
from

Conversation

42milez
Copy link

@42milez 42milez commented Oct 29, 2021

Issue #, if available:

N/A

Description of changes:

In the latest version (1.2.279.0), fmt.Fprintf() writes to os.Stdout in any context. In some cases, this can lead to unexpected behaviors of the application which works with Session Manager.

In my case, paramiko, a SSH implementaiton for Python, reads the output (e.g. session.go:193) of session-manager-plugin from stdout during the wait for SSH banner.

As the result, paramiko breaks out the loop of wating for SSH banner, and the banner_timeout parameter is reset to paramiko's default (e.g. transport.py:2201). For this reason, I cannot connect to a server via SSH through the tunnel of Session Manager in the environment that takes a long time to establish the connection.

So, if possible, I would like to make a change so that fmt.Fprint() writes to stderr.

Additional Information:

A similar topic is being discussed in the repository of aws-ssm-agent.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@42milez 42milez changed the title Use os.Stderr instead of os.Stdout in fmt.Fprintf() Use os.Stderr instead of os.Stdout with fmt.Fprintf() Nov 11, 2021
} else {
fmt.Fprintf(os.Stdout, "\n\nSessionId: %s : %s\n\n", sessionId, channelClosedMessage.Output)
fmt.Fprintf(os.Stderr, "\n\nSessionId: %s : %s\n\n", sessionId, channelClosedMessage.Output)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there two \n characters here?

@ioquatix
Copy link

@Yangtao-Hua @yuting-fan can we merge this?

@AronNovak
Copy link

To be able to use session manager for various tooling, it would be essential to merge this.

@@ -190,7 +190,7 @@ func ValidateInputAndStartSession(args []string, out io.Writer) {

//Execute create data channel and start the session
func (s *Session) Execute(log log.T) (err error) {
fmt.Fprintf(os.Stdout, "\nStarting session with SessionId: %s\n", s.SessionId)
fmt.Fprintf(os.Stderr, "\nStarting session with SessionId: %s\n", s.SessionId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many just notification messages like these. e.g. Start/stop session, or call out KMS enabled. Not sure changing the behavior to write to Stderr is a better solution.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a quiet mode to not print those messages

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better behaviour because it doesn't mix the output with normal output. Say, you call a remote script to generate CSV. Right now you end up with log messages mixed with CSV output. With this change, the log messages go to stderr and aren't mixed with stdout.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks all, will test it and support the change in next release.

Copy link
Contributor

@Yangtao-Hua Yangtao-Hua Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, just a quick update, we cannot merge this change as plan, since many customer are trying to extract info from the Stdout. e.g. plugin version. This change will break their current user experience. As @tapajos mentioned, we may need a quiet mode, or reduce some logs, change part of them to Stderr. Team will work on resolve this issue in a graceful way later. Thanks for understanding.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, I am in awe of what some people do... yes, please introduce a quiet mode. What is the ETA?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yangtao-Hua would #94 provide what you need to avoid breaking current user experience?

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.

6 participants