Use isErrClosed in Server.Serve

This commit is contained in:
Simon Ser 2021-10-05 14:02:59 +02:00
parent e4f22a8f40
commit 1626ffb97b

View File

@ -6,7 +6,6 @@ import (
"mime"
"net"
"net/http"
"strings"
"sync"
"sync/atomic"
"time"
@ -197,8 +196,7 @@ func (s *Server) Serve(ln net.Listener) error {
for {
conn, err := ln.Accept()
// TODO: use net.ErrClosed when available
if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
if isErrClosed(err) {
return nil
} else if err != nil {
return fmt.Errorf("failed to accept connection: %v", err)