diff --git a/README.md b/README.md index d64924e..ce8ebdc 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [David Hamilton](https://github.com/dihamilton) * [adwpc](https://github.com/adwpc) * [Ori Bernstein](https://eigenstate.org) +* [Sam Lancia](https://github.com/nerd2) ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/gather.go b/gather.go index 42c3a35..fe4fb60 100644 --- a/gather.go +++ b/gather.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "fmt" "net" + "reflect" "sync" "time" @@ -22,8 +23,8 @@ type closeable interface { // Close a net.Conn and log if we have a failure func closeConnAndLog(c closeable, log logging.LeveledLogger, msg string) { - if c == nil { - log.Warnf("Conn is not allocated") + if c == nil || (reflect.ValueOf(c).Kind() == reflect.Ptr && reflect.ValueOf(c).IsNil()) { + log.Warnf("Conn is not allocated (%s)", msg) return } diff --git a/gather_test.go b/gather_test.go index bbf9878..124866a 100644 --- a/gather_test.go +++ b/gather_test.go @@ -256,3 +256,15 @@ func TestTURNConcurrency(t *testing.T) { runTest(ProtoTypeUDP, SchemeTypeTURNS, nil, serverListener, serverPort) }) } + +func TestCloseConnLog(t *testing.T) { + a, err := NewAgent(&AgentConfig{}) + assert.NoError(t, err) + + closeConnAndLog(nil, a.log, "normal nil") + + var nc *net.UDPConn + closeConnAndLog(nc, a.log, "nil ptr") + + assert.NoError(t, a.Close()) +}