1
0
Эх сурвалжийг харах

happy-eyeballs: Move happy_eyeballs_destroy to a thread

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.
Richard Stanway 1 жил өмнө
parent
commit
78ffd99ab1

+ 18 - 3
shared/happy-eyeballs/happy-eyeballs.c

@@ -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
@@ -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;
 }