Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit bd47d0c

Browse files
SataQiulowzj
authored andcommitted
proxy: do not log error messages when http Server is closed
Signed-off-by: SataQiu <[email protected]>
1 parent bacc34b commit bd47d0c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

dfdaemon/proxy/proxy.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ func (proxy *Proxy) handleHTTPS(w http.ResponseWriter, r *http.Request) {
403403
// We have to wait until the connection is closed
404404
wg := sync.WaitGroup{}
405405
wg.Add(1)
406-
if err := http.Serve(&singleUseListener{&customCloseConn{sConn, wg.Done}}, rp); err != nil {
406+
// NOTE: http.Serve always returns a non-nil error
407+
if err := http.Serve(&singleUseListener{&customCloseConn{sConn, wg.Done}}, rp); err != errServerClosed && err != http.ErrServerClosed {
407408
logrus.Errorf("failed to accept incoming HTTP connections: %v", err)
408409
}
409410
wg.Wait()
@@ -455,9 +456,13 @@ type singleUseListener struct {
455456
c net.Conn
456457
}
457458

459+
// errServerClosed is returned by the singleUseListener's Accept method
460+
// when it receives the subsequent calls after the first Accept call
461+
var errServerClosed = errors.New("singleUseListener: Server closed")
462+
458463
func (l *singleUseListener) Accept() (net.Conn, error) {
459464
if l.c == nil {
460-
return nil, errors.New("closed")
465+
return nil, errServerClosed
461466
}
462467
c := l.c
463468
l.c = nil

0 commit comments

Comments
 (0)