Commit cdbfa916da for asterisk.org

commit cdbfa916da5c0d2df50bcac179b775738451baf8
Author: Andrea Guglielmini <andrea@guglio.net>
Date:   Wed Nov 25 11:13:23 2026 +0100

    chan_websocket: Hold the instances lock when looking up incoming connections.

    incoming_ws_http_callback() and incoming_ws_established_cb() look up the
    connection with ao2_weakproxy_find(..., OBJ_SEARCH_KEY | OBJ_NOLOCK)
    without holding the lock of the instances container. OBJ_NOLOCK tells
    ao2 that the caller already holds it, so on this RWLOCK container
    __adjust_lock() deduces the caller's lock from the shared num_lockers
    counter. When the lookup overlaps a writer in another thread
    (websocket_new() or instance_proxy_cb()), the HTTP thread "restores" a
    lock it never took: it unlocks a lock it does not own and locks one it
    never releases.

    From then on every writer of the container blocks: Dial() to a WebSocket
    channel never returns and finished WebSocket channels are never
    destroyed, while incoming connections keep getting 404 because the
    lookups take no lock. Only a restart recovers.

    Let ao2_weakproxy_find() take and release the read lock itself.

    Resolves: #2344

diff --git a/channels/chan_websocket.c b/channels/chan_websocket.c
index d80ab07819..aa9454d825 100644
--- a/channels/chan_websocket.c
+++ b/channels/chan_websocket.c
@@ -1993,7 +1993,7 @@ static void incoming_ws_established_cb(struct ast_websocket *ast_ws_session,
 		return;
 	}

-	instance = ao2_weakproxy_find(instances, connection_id, OBJ_SEARCH_KEY | OBJ_NOLOCK, "");
+	instance = ao2_weakproxy_find(instances, connection_id, OBJ_SEARCH_KEY, "");
 	if (!instance) {
 		/*
 		 * This also can't really happen because websocket_http_callback won't
@@ -2057,7 +2057,7 @@ static int incoming_ws_http_callback(struct ast_tcptls_session_instance *ser,
 	 * only the path components after that in the 'uri' parameter.
 	 * This should leave only the connection id without a leading '/'.
 	 */
-	instance = ao2_weakproxy_find(instances, uri, OBJ_SEARCH_KEY | OBJ_NOLOCK, "");
+	instance = ao2_weakproxy_find(instances, uri, OBJ_SEARCH_KEY, "");
 	if (!instance) {
 		ast_log(LOG_WARNING, "%s: WebSocket instance not found\n", uri);
 		ast_http_error(ser, 404, "Not found", "WebSocket instance not found");