Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 0717779

Browse files
committed
api, common, db4s, webui: Don't log TLS handshake errors
We get a fair amount of (useless) TLS handshake error messages filling our logs. This commit introduces a custom http error log function to filter them out.
1 parent 3311af4 commit 0717779

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func main() {
150150
}
151151
srv := &http.Server{
152152
Addr: com.Conf.Api.BindAddress,
153+
ErrorLog: com.HttpErrorLog(),
153154
TLSConfig: newTLSConfig,
154155
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
155156
}

common/util.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ import (
1818
"github.com/minio/minio-go"
1919
)
2020

21+
var (
22+
// Our custom http error logger
23+
httpErrorLogger *log.Logger
24+
)
25+
26+
// FilteringErrorLogWriter is a custom error logger for our http servers, to filter out the copious
27+
// 'TLS handshake error' messages we're getting.
28+
// Very heavily based on: https://github.com/golang/go/issues/26918#issuecomment-974257205
29+
type FilteringErrorLogWriter struct{}
30+
31+
func (*FilteringErrorLogWriter) Write(msg []byte) (int, error) {
32+
z := string(msg)
33+
if !(strings.HasPrefix(z, "http: TLS handshake error") && strings.HasSuffix(z, ": EOF\n")) {
34+
err := httpErrorLogger.Output(0, z)
35+
if err != nil {
36+
log.Println(err)
37+
}
38+
}
39+
return len(msg), nil
40+
}
41+
42+
// Filter out the copious 'TLS handshake error' messages we're getting
43+
func HttpErrorLog() *log.Logger {
44+
httpErrorLogger = log.New(&FilteringErrorLogWriter{}, "", log.LstdFlags)
45+
return httpErrorLogger
46+
}
47+
2148
// AddDatabase is handles database upload processing
2249
func AddDatabase(loggedInUser, dbOwner, dbName string, createBranch bool, branchName,
2350
commitID string, accessType SetAccessType, licenceName, commitMsg, sourceURL string, newDB io.Reader,

db4s/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func main() {
107107
}
108108
newServer := &http.Server{
109109
Addr: ":" + fmt.Sprint(com.Conf.DB4S.Port),
110+
ErrorLog: com.HttpErrorLog(),
110111
Handler: gz.GzipHandler(mux),
111112
TLSConfig: newTLSConfig,
112113
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),

webui/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,8 @@ func main() {
35063506
// Start webUI server
35073507
log.Printf("WebUI server starting on https://%s\n", com.Conf.Web.ServerName)
35083508
srv := &http.Server{
3509-
Addr: com.Conf.Web.BindAddress,
3509+
Addr: com.Conf.Web.BindAddress,
3510+
ErrorLog: com.HttpErrorLog(),
35103511
TLSConfig: &tls.Config{
35113512
MinVersion: tls.VersionTLS12, // TLS 1.2 is now the lowest acceptable level
35123513
},

0 commit comments

Comments
 (0)