Skip to content

Commit

Permalink
fix: check if net err is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenrinzema committed Dec 2, 2023
1 parent 4ebe2bc commit 04dce19
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"net"
"sync"
Expand Down Expand Up @@ -88,7 +89,6 @@ func (srv *Server) ListenAndServe(address string) error {
// preconfigured configurations. The given listener will be closed once the
// server is gracefully closed.
func (srv *Server) Serve(listener net.Listener) error {
defer listener.Close()
defer srv.logger.Info("closing server")

srv.logger.Info("serving incoming connections", slog.String("addr", listener.Addr().String()))
Expand All @@ -107,6 +107,10 @@ func (srv *Server) Serve(listener net.Listener) error {

for {
conn, err := listener.Accept()
if errors.Is(err, net.ErrClosed) {
return nil
}

if err != nil {
return err
}
Expand Down

0 comments on commit 04dce19

Please sign in to comment.