Skip to content

Commit

Permalink
Ignore "use of closed network connection" errors
Browse files Browse the repository at this point in the history
Every time the server returns a response to the client it calls
BuildAndSend(), which assumes that the other side is still listening
and returns a "use of closed network connection" error when it does
not. This error always shows up when the client disconnects first,
which is totally normal, but messes up logs and fires stale
alarms. This commit silences these errors.

I am fairly certain that this change does not break anything. Yet,
please give feedback.
  • Loading branch information
rg0now authored and stv0g committed Feb 23, 2023
1 parent b0f8b53 commit bec86f9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"crypto/md5" //nolint:gosec,gci
"errors"
"fmt"
"io"
"math/rand"
Expand All @@ -16,7 +17,6 @@ import (
const (
maximumAllocationLifetime = time.Hour // https://tools.ietf.org/html/rfc5766#section-6.2 defines 3600 seconds recommendation
nonceLifetime = time.Hour // https://tools.ietf.org/html/rfc5766#section-4

)

func randSeq(n int) string {
Expand Down Expand Up @@ -46,6 +46,10 @@ func buildAndSend(conn net.PacketConn, dst net.Addr, attrs ...stun.Setter) error
return err
}
_, err = conn.WriteTo(msg.Raw, dst)
if errors.Is(err, net.ErrClosed) {
return nil
}

return err
}

Expand Down

0 comments on commit bec86f9

Please sign in to comment.