Skip to content

Commit

Permalink
happy-eyeballs: Move happy_eyeballs_destroy to a thread
Browse files Browse the repository at this point in the history
On Windows, shutdown() will not interrupt a blocking connect() call, so
happy_eyeballs_destroy could block until the remaining candidates timed
out. As happy_eyeballs_destroy is called in the RTMP connect path, this
would stall the RTMP connection and cause the winning candidate's socket
to be disconnected due to a timeout.

(cherry picked from commit 78ffd99)
  • Loading branch information
notr1ch authored and RytoEX committed Aug 15, 2024
1 parent 09d2e37 commit e494f93
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions deps/happy-eyeballs/happy-eyeballs.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,11 @@ int happy_eyeballs_timedwait(struct happy_eyeballs_ctx *context,
return status;
}

int happy_eyeballs_destroy(struct happy_eyeballs_ctx *context)
static void *destroy_thread(void *param)
{
if (context == NULL)
return STATUS_INVALID_ARGUMENT;
struct happy_eyeballs_ctx *context = param;

os_set_thread_name("happy-eyeballs destroy thread");
#ifdef _WIN32
#define SHUT_RDWR SD_BOTH
#else
Expand Down Expand Up @@ -698,6 +698,21 @@ int happy_eyeballs_destroy(struct happy_eyeballs_ctx *context)

da_free(context->candidates);
free(context);

return NULL;
}

int happy_eyeballs_destroy(struct happy_eyeballs_ctx *context)
{
if (context == NULL)
return STATUS_INVALID_ARGUMENT;

/* The destroy happens asynchronously in another thread due to the
* connect() call blocking on Windows. */
pthread_t thread;
pthread_create(&thread, NULL, destroy_thread, context);
pthread_detach(thread);

return STATUS_SUCCESS;
}

Expand Down

0 comments on commit e494f93

Please sign in to comment.