paullouisageneau / libjuice

JUICE is a UDP Interactive Connectivity Establishment library
Mozilla Public License 2.0
434 stars 82 forks source link

Fix crash and connection failure when invalid bind_address is set #274

Closed mojyack closed 1 month ago

mojyack commented 1 month ago

This PR has two patches to fix bugs around udp_create_socket error handling.

The first one is to fix issue where: If conn_poll_init fails, for example by setting an invalid bind address, and it is the only agent at the time, all newly created agents will fail until another agent is created and deleted.

See this sample code connectivity-bind-address.c.gz. The former test_connectivity_with_bind_address("8.8.8.8") will fail of course since 8.8.8.8 is an invalid local address(for most computers). But then the latter test_connectivity_with_bind_address(NULL) will also fail. And if this is executed before 8.8.8.8 case, it will succeed.

This is because the connections thread has already exited, but the registry is not re-created in subsequent conn_create. The patch fixes this by releasing registry when init_func fails.

The second one is to fix crash when registry_init_func fails when concurrency_mode is set to MUX or THREAD. You can easily test this by adding config1.concurrency_mode = JUICE_CONCURRENCY_MODE_MUX to attached example. The patch fixes this by returning explicit error value from acquire_registry and checking it.