From 9d6d0050433c53d9094aaaf8ff181a5971c9a7d4 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Mon, 25 Jul 2022 12:30:22 +0100 Subject: [PATCH 1/3] Stop logging EOFs and exit(1)s in ssh handler 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 --- modules/ssh/ssh.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 2affeb781a998..755387236260f 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -11,6 +11,7 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" + "errors" "fmt" "io" "net" @@ -142,10 +143,12 @@ 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) + 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) { log.Error("Session failed to exit. %s", err) } } From 89fe4e87539b00ec17e8ffd14f6bc0a2627be5eb Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 27 Jul 2022 07:15:17 +0100 Subject: [PATCH 2/3] Update modules/ssh/ssh.go --- modules/ssh/ssh.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 755387236260f..3aa0d20f4614c 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -143,6 +143,8 @@ func sessionHandler(session ssh.Session) { // Wait for the command to exit and log any errors we get err = cmd.Wait() if err != nil { + // 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) } From 2b6b73c48e03b6971d0d019620253f02fb4e727a Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 27 Jul 2022 18:18:14 +0100 Subject: [PATCH 3/3] placate lint Signed-off-by: Andrew Thornton --- modules/ssh/ssh.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 3aa0d20f4614c..bffe29f4c385b 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -144,7 +144,7 @@ func sessionHandler(session ssh.Session) { err = cmd.Wait() if err != nil { // Cannot use errors.Is here because ExitError doesn't implement Is - // Thus errors.Is will do equality test NOT type comparison + // Thus errors.Is will do equality test NOT type comparison if _, ok := err.(*exec.ExitError); !ok { log.Error("SSH: Wait: %v", err) }