Close hangs app when WithNoConnClose
When stun connection is created from existing connection, and WithNoConnClose is provided, Close hangs app.
I have the same issue. Debugging showed that Close waits for readUntilClosed go-routing to exit, but that go-routine is blocked on ReadFrom call here https://github.com/pion/stun/blob/0f7f72b905d54eaf8e477af78c6a3d42f54ea217/client.go#L327
Workaround is to call SetReadDeadline(time.Now()) before calling Close for the stun.Client. It causes ReadFrom to immediately exit.
@hashok Calling SetReadDeadline(time.Now()) closes the connection.
@adsko It shouldn't do that. Make sure you call SetReadDeadline(time.Time{}) on the underlying connection after stun connection is closed to restore the original behavior of the underlying connection.
How do we fix this issue?
Setting the read deadline in Close() is not feasible since the connection only implements the following interface:
// Connection wraps Reader, Writer and Closer interfaces.
type Connection interface {
io.Reader
io.Writer
io.Closer
}
We could call c.wg.Done() manually to unblock the c.wg.Wait() in Close().
However, that would leave us with a leaked Goroutine and might cause some panic if the connection still ends up receiving data while the client has been closed?