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

Stop logging EOFs and exit(1)s in ssh handler (#20476) #20529

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -142,10 +143,14 @@ func sessionHandler(session ssh.Session) {
// Wait for the command to exit and log any errors we get
err = cmd.Wait()
if err != nil {
log.Error("SSH: Wait: %v", err)
// Cannot use errors.Is here because ExitError doesn't implement Is
// Thus errors.Is will do equality test NOT type comparison
if _, ok := err.(*exec.ExitError); !ok {
log.Error("SSH: Wait: %v", err)
}
}

if err := session.Exit(getExitStatusFromError(err)); err != nil {
if err := session.Exit(getExitStatusFromError(err)); err != nil && !errors.Is(err, io.EOF) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using error.Is correct here? golang/go#39155 suggests that io.EOF never should be wrapped(and currently standard library shouldn't do that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just because io.EOF shouldn't be wrapped does not mean that it cannot be wrapped and errors.Is will still work on it.

We don't care about io.EOF. we don't care about errors that accidentally wrap io.EOF.

Therefore we should ignore them.

Therefore errors.Is is correct

log.Error("Session failed to exit. %s", err)
}
}
Expand Down