Skip to content

Commit

Permalink
handle "connection reset by peer" error
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinz01 committed May 3, 2024
1 parent e127864 commit 6a19acb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"log"
"net"
"strings"
"syscall"
)

Expand Down Expand Up @@ -133,8 +134,9 @@ func (s *LDAPServer) handleConnection(c net.Conn) {
msg, err := ldapConn.ReadMessage()
ldapConn.tlsStarting.RUnlock()
if err != nil {
if errors.Is(err, syscall.Errno(0x2746)) { // Windows: An existing connection was forcibly closed by the client
log.Println("Connection was reset by the client.")
if errors.Is(err, syscall.Errno(0x2746)) || // Windows: An existing connection was forcibly closed by the client
strings.HasSuffix(err.Error(), "connection reset by peer") {
log.Println("Connection was reset.")
ldapConn.Close()
return
} else {
Expand Down

0 comments on commit 6a19acb

Please sign in to comment.