Skip to content

Commit c9c5bd8

Browse files
authored
Stop logging EOFs and exit(1)s in ssh handler (#20476)
The code in modules/ssh/ssh.go:sessionHandler() currently cause an error to be logged if `gitea serv` exits with a exit(1). This logging is useless because the accompanying stderr is not provided and in any case the exit(1) is most likely due to permissions errors. Further it then causes the EOF to be logged - even though this is not helpful. This PR simply checks the errors returned and stops logging them. In the case of misconfigurations causing `gitea serv` to fail with exit(1) the current logging is not helpful at determining this and users should simply review the message passed over the ssh connection. Fix #20473 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 9691d43 commit c9c5bd8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/ssh/ssh.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"crypto/rsa"
1212
"crypto/x509"
1313
"encoding/pem"
14+
"errors"
1415
"fmt"
1516
"io"
1617
"net"
@@ -142,10 +143,14 @@ func sessionHandler(session ssh.Session) {
142143
// Wait for the command to exit and log any errors we get
143144
err = cmd.Wait()
144145
if err != nil {
145-
log.Error("SSH: Wait: %v", err)
146+
// Cannot use errors.Is here because ExitError doesn't implement Is
147+
// Thus errors.Is will do equality test NOT type comparison
148+
if _, ok := err.(*exec.ExitError); !ok {
149+
log.Error("SSH: Wait: %v", err)
150+
}
146151
}
147152

148-
if err := session.Exit(getExitStatusFromError(err)); err != nil {
153+
if err := session.Exit(getExitStatusFromError(err)); err != nil && !errors.Is(err, io.EOF) {
149154
log.Error("Session failed to exit. %s", err)
150155
}
151156
}

0 commit comments

Comments
 (0)