Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close hangs app when WithNoConnClose #80

Open
adsko opened this issue Apr 5, 2021 · 4 comments
Open

Close hangs app when WithNoConnClose #80

adsko opened this issue Apr 5, 2021 · 4 comments

Comments

@adsko
Copy link

adsko commented Apr 5, 2021

When stun connection is created from existing connection, and WithNoConnClose is provided, Close hangs app.

@hashok
Copy link

hashok commented Apr 15, 2021

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

stun/client.go

Line 327 in 0f7f72b

_, err := m.ReadFrom(c.c)

Workaround is to call SetReadDeadline(time.Now()) before calling Close for the stun.Client. It causes ReadFrom to immediately exit.

@adsko
Copy link
Author

adsko commented Apr 15, 2021

@hashok Calling SetReadDeadline(time.Now()) closes the connection.

@hashok
Copy link

hashok commented Apr 16, 2021

@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.

@stv0g
Copy link
Member

stv0g commented Nov 15, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants