]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_sip: Give more time for TCP/TLS threads to stop. 02/2702/4
authorJoshua Colp <jcolp@digium.com>
Tue, 26 Apr 2016 16:13:14 +0000 (13:13 -0300)
committerJoshua Colp <jcolp@digium.com>
Tue, 26 Apr 2016 16:16:36 +0000 (11:16 -0500)
The unload process currently tells each TCP/TLS to terminate but
does not wait for them to do so. This introduces a race condition
where the container holding the threads may be destroyed before
the threads are able to remove themselves from it. When they
finally do the container is invalid and can't be used causing a
crash.

A previous change existed which waited a bit to wait for any
stranglers to finish. This change extends this and waits longer.

ASTERISK-25961 #close

Change-Id: Idc6262b670ca49ede32061159e323b7b63c6f3c6

channels/chan_sip.c

index d927f06e39381d9a0338b4dcd48ec517c6b408ef..9e5a7fd83c85838e529ed8c5b53301ec90e9a756 100644 (file)
@@ -35298,7 +35298,7 @@ static int unload_module(void)
        struct sip_pvt *p;
        struct sip_threadinfo *th;
        struct ao2_iterator i;
-       int wait_count;
+       struct timeval start;
 
        ast_sip_api_provider_unregister();
 
@@ -35450,11 +35450,11 @@ static int unload_module(void)
         * joinable.  They can die on their own and remove themselves
         * from the container thus resulting in a huge memory leak.
         */
-       wait_count = 1000;
-       while (ao2_container_count(threadt) && --wait_count) {
+       start = ast_tvnow();
+       while (ao2_container_count(threadt) && (ast_tvdiff_sec(ast_tvnow(), start) < 5)) {
                sched_yield();
        }
-       if (!wait_count) {
+       if (ao2_container_count(threadt)) {
                ast_debug(2, "TCP/TLS thread container did not become empty :(\n");
        }