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

Concurrency issues when creating a connection #171

Open
hateeyan opened this issue Jan 2, 2025 · 4 comments
Open

Concurrency issues when creating a connection #171

hateeyan opened this issue Jan 2, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@hateeyan
Copy link
Contributor

hateeyan commented Jan 2, 2025

When using DialogUA to send Invite concurrently, the connection will be created multiple times.

The log shows that the connection was created multiple times. Because the port was already bound, one of the requests failed.

failed to send sip invite: listen udp 10.9.232.246:5020: bind: address already in use
{"level":"debug","caller":"transportlayer","host":"10.9.232.246","port":5020,"network":"udp","time":"2025-01-02T10:21:12+08:00","message":"Via header used for creating connection"}
{"level":"debug","caller":"transportlayer","host":"10.9.232.246","port":5020,"network":"udp","time":"2025-01-02T10:21:12+08:00","message":"Via header used for creating connection"}
{"level":"debug","caller":"transport<UDP>","raddr":"10.9.232.246:8060","time":"2025-01-02T10:21:12+08:00","message":"New connection"}

We may need to add a mutex in CreateConnection and check whether the connection has been created by another goroutine.

l.log.Debug().Str("host", viaHop.Host).Int("port", viaHop.Port).Str("network", network).Msg("Via header used for creating connection")
c, err = transport.CreateConnection(ctx, laddr, raddr, l.handleMessage)
if err != nil {
return nil, err
}

@emiago
Copy link
Owner

emiago commented Jan 2, 2025

Hi @hateeyan Thanks for reporting this. I see now issue. I think this needs fix on way transport connection pool is used. Adding into list to fix

@emiago emiago mentioned this issue Jan 2, 2025
@emiago emiago added bug Something isn't working breaking change labels Jan 13, 2025
@emiago
Copy link
Owner

emiago commented Feb 17, 2025

NOTE: Issue is only related for fixed IP. Recommendation is to build listener first.
Diago does this more nicely, as generally running full client requires both directions.
We may not introduce this contention as can be fixed with different usage.

@hateeyan Have you tried approach creating listener first, and then reusing his IP?

@hateeyan
Copy link
Contributor Author

@hateeyan Have you tried approach creating listener first, and then reusing his IP?

@emiago Yeah, that's what I'm doing now.
But for a client, it is a little strange to create a listener first. Anyway, it is not a big problem.

@emiago
Copy link
Owner

emiago commented Feb 18, 2025

@hateeyan yes I understand. It makes sense for non dialogs, but in dialogs you need to listen.
I will leave this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants