Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

videoroom: Release some references created by remote publishers #3359

Closed
wants to merge 2 commits into from

Conversation

fancycode
Copy link
Contributor

@fancycode fancycode commented Apr 23, 2024

Fixed some cases where the rtp_forwarders map was created without the destructor function. This resulted in the forwarders not being released when the publisher got destroyed.

@lminiero
Copy link
Member

I don't think that's wise: the map you see in the publisher's struct is only a shallow reference, since the actual map is stored in the publisher_stream struct, and we do have the janus_rtp_forwarder_destroy callback for the hashtable there. We risk a double free with the additions you put there I believe, or access to broken memory if the instance was destroyed already.

@fancycode
Copy link
Contributor Author

Thanks for your feedback. I had a problem where the forwarders were not released properly when my controller websocket connection was closed and the patch fixed this.

So maybe my problem must be fixed differently - I'll do some more tests and provide an update here.

@lminiero
Copy link
Member

forwarders were not released properly when my controller websocket connection was closed

I'd check if the cause is that there are publisher streams (and maybe entire publishers) whose references never get to zero causing their forwarders not to be destroyed either. Did you check by uncommenting the REFCOUNT_DEBUG define in refcount.h already? That will enable refcount debugging, which will make logs much more verbose, but will allow you to track references as they go up and down, and will print a summary of what's still there at shutdown (after you try a clean shutdown, that is, so after you closed all sessions/handles properly and shut Janus down expecting everything to be deallocated already).

@fancycode fancycode force-pushed the destroy-forwarders branch from 508e84d to 00e3d3d Compare April 24, 2024 13:46
@fancycode fancycode changed the title videoroom: Always destroy forwarders on hash map removal. videoroom: Release some references created by remote publishers Apr 24, 2024
Copy link
Contributor Author

@fancycode fancycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some more tests with refcount debugging enabled. My initial assumption was wrong, and the problem was actually in the remote publishers that stayed active.

@@ -13421,7 +13428,7 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) {
}
g_list_free(subscribers);
/* Free streams */
g_list_free(publisher->streams);
g_list_free_full(publisher->streams, (GDestroyNotify)(janus_videoroom_publisher_stream_unref));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other places use janus_videoroom_publisher_stream_destroy but as this is also used for streams_byid, the reference would not be decreased again, resulting in a leak.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be a destroy, then, and the related maps both be unrefs. Besides, if that's the rationale for the list, then it should not only be fixed for remote publishers, but for all of them, since we do a simple g_list_free(participant->streams) in janus_videoroom_hangup_media_internal too. That said, we should thread carefully here, as I don't remember seeing leaks normally (all my local builds use libasan).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some debugging and it looks like that at the time janus_videoroom_subscriber_free or janus_videoroom_publisher_free are called, the streams list and the streams_byid / streams_bymid hashmaps are empty - at least in the scenarios I tested.

However at the end of the remove publisher thread, the streams list is not empty, resulting in the leak if janus_videoroom_publisher_stream_destroy is used.

@@ -2433,6 +2433,8 @@ static void janus_videoroom_publisher_dereference_nodebug(janus_videoroom_publis
janus_refcount_decrease_nodebug(&p->ref);
}

static void janus_videoroom_session_destroy(janus_videoroom_session *session);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you want the forward declaration or if one of the two functions should be moved.

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of notes inline.

@@ -2468,6 +2470,9 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) {
}
}
janus_mutex_unlock(&p->rtp_forwarders_mutex);
/* Release dummy session of the forwarder */
if(p->session && p->session->handle == NULL)
janus_videoroom_session_destroy(p->session);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here, and why does this mention a dummy session? This is not a function only used for dummy publishers: it's the destroy function for all publishers, and is not meant to be called directly, it's the callback for the cleanup from sessions. At the very least, this should have a p->dummy check too to ensure it's not done on regular publishers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the session created here:

/* We create a dummy session first, that's not actually bound to anything */

It belongs to a regular publisher, so p->dummy will be false, I'll check for p->remote which seems to be the flag to use here.

@@ -13421,7 +13428,7 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) {
}
g_list_free(subscribers);
/* Free streams */
g_list_free(publisher->streams);
g_list_free_full(publisher->streams, (GDestroyNotify)(janus_videoroom_publisher_stream_unref));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be a destroy, then, and the related maps both be unrefs. Besides, if that's the rationale for the list, then it should not only be fixed for remote publishers, but for all of them, since we do a simple g_list_free(participant->streams) in janus_videoroom_hangup_media_internal too. That said, we should thread carefully here, as I don't remember seeing leaks normally (all my local builds use libasan).

@fancycode fancycode force-pushed the destroy-forwarders branch from 00e3d3d to e02d752 Compare July 4, 2024 20:37
Copy link
Contributor Author

@fancycode fancycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the really late reply, I added a comment to your question and updated the dummy session check.

@@ -2468,6 +2470,9 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) {
}
}
janus_mutex_unlock(&p->rtp_forwarders_mutex);
/* Release dummy session of the forwarder */
if(p->session && p->session->handle == NULL)
janus_videoroom_session_destroy(p->session);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the session created here:

/* We create a dummy session first, that's not actually bound to anything */

It belongs to a regular publisher, so p->dummy will be false, I'll check for p->remote which seems to be the flag to use here.

@@ -13421,7 +13428,7 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) {
}
g_list_free(subscribers);
/* Free streams */
g_list_free(publisher->streams);
g_list_free_full(publisher->streams, (GDestroyNotify)(janus_videoroom_publisher_stream_unref));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some debugging and it looks like that at the time janus_videoroom_subscriber_free or janus_videoroom_publisher_free are called, the streams list and the streams_byid / streams_bymid hashmaps are empty - at least in the scenarios I tested.

However at the end of the remove publisher thread, the streams list is not empty, resulting in the leak if janus_videoroom_publisher_stream_destroy is used.

@fancycode
Copy link
Contributor Author

@lminiero not sure if you have seen my latest comments. Please let me know you want more changes or if / how I should debug this further.

@lminiero
Copy link
Member

lminiero commented Oct 4, 2024

@fancycode apologies, I haven't delved in detail in them yet, and I've been a bit busy lately. I'll have a look next week and get back to you: if that doesn't happen, please feel free to shout at me 😄

@fancycode
Copy link
Contributor Author

@lminiero No worries, take your time.

@lminiero
Copy link
Member

@fancycode could you resolve the conflict? I think it was caused by #3447 since that change impacted remote publishers as well.

@fancycode
Copy link
Contributor Author

@fancycode could you resolve the conflict? I think it was caused by #3447 since that change impacted remote publishers as well.

Done

@atoppi
Copy link
Member

atoppi commented Nov 5, 2024

Adding the report from ASan (commit 51fe38a)

==19349==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1072 byte(s) in 2 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f689bdb7f03 in janus_videoroom_process_synchronous_request plugins/janus_videoroom.c:7737
    #3 0x7f689bddd3f0 in janus_videoroom_handle_message plugins/janus_videoroom.c:8269
    #4 0x55ae9fd7b933 in janus_process_incoming_request /home/atoppi/src/janus-gateway/src/janus.c:1826
    #5 0x55ae9fdab61b in janus_transport_task /home/atoppi/src/janus-gateway/src/janus.c:3550
    #6 0x7f68c3b78541 in g_thread_pool_thread_proxy ../../../glib/gthreadpool.c:336
    #7 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #8 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #9 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Direct leak of 264 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f689bcb5f01 in janus_videoroom_init plugins/janus_videoroom.c:3742
    #3 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #4 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #5 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #6 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Direct leak of 80 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f689bdb5e03 in janus_videoroom_process_synchronous_request plugins/janus_videoroom.c:7686
    #3 0x7f689bddd3f0 in janus_videoroom_handle_message plugins/janus_videoroom.c:8269
    #4 0x55ae9fd7b933 in janus_process_incoming_request /home/atoppi/src/janus-gateway/src/janus.c:1826
    #5 0x55ae9fdab61b in janus_transport_task /home/atoppi/src/janus-gateway/src/janus.c:3550
    #6 0x7f68c3b78541 in g_thread_pool_thread_proxy ../../../glib/gthreadpool.c:336
    #7 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #8 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #9 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 192 byte(s) in 2 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b2b44a in g_hash_table_new_full ../../../glib/ghash.c:1016
    #3 0x7f689bdbb988 in janus_videoroom_process_synchronous_request plugins/janus_videoroom.c:7829
    #4 0x7f689bddd3f0 in janus_videoroom_handle_message plugins/janus_videoroom.c:8269
    #5 0x55ae9fd7b933 in janus_process_incoming_request /home/atoppi/src/janus-gateway/src/janus.c:1826
    #6 0x55ae9fdab61b in janus_transport_task /home/atoppi/src/janus-gateway/src/janus.c:3550
    #7 0x7f68c3b78541 in g_thread_pool_thread_proxy ../../../glib/gthreadpool.c:336
    #8 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #9 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #10 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b2b44a in g_hash_table_new_full ../../../glib/ghash.c:1016
    #3 0x7f689bcc043f in janus_videoroom_init plugins/janus_videoroom.c:3953
    #4 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #5 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #6 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #7 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b2b44a in g_hash_table_new_full ../../../glib/ghash.c:1016
    #3 0x7f689bcc0224 in janus_videoroom_init plugins/janus_videoroom.c:3949
    #4 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #5 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #6 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #7 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b2b44a in g_hash_table_new_full ../../../glib/ghash.c:1016
    #3 0x7f689bcc02ce in janus_videoroom_init plugins/janus_videoroom.c:3951
    #4 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #5 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #6 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #7 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b30554 in g_hash_table_maybe_make_big_keys_or_values ../../../glib/ghash.c:880
    #3 0x7f68c3b30554 in g_hash_table_maybe_make_big_keys_or_values ../../../glib/ghash.c:872
    #4 0x7f68c3b30554 in g_hash_table_ensure_keyval_fits ../../../glib/ghash.c:939
    #5 0x7f68c3b30554 in g_hash_table_insert_node ../../../glib/ghash.c:1298
    #6 0x7f68c3b30d45 in g_hash_table_insert_internal ../../../glib/ghash.c:1572
    #7 0x7f68c3b30d45 in g_hash_table_insert ../../../glib/ghash.c:1601
    #8 0x7f689be2ec9b in janus_videoroom_handler plugins/janus_videoroom.c:9642
    #9 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #10 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #11 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f68c3b2b3fc in g_hash_table_setup_storage ../../../glib/ghash.c:536
    #3 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #4 0x7f689bdbb988 in janus_videoroom_process_synchronous_request plugins/janus_videoroom.c:7829
    #5 0x7f689bddd3f0 in janus_videoroom_handle_message plugins/janus_videoroom.c:8269
    #6 0x55ae9fd7b933 in janus_process_incoming_request /home/atoppi/src/janus-gateway/src/janus.c:1826
    #7 0x55ae9fdab61b in janus_transport_task /home/atoppi/src/janus-gateway/src/janus.c:3550
    #8 0x7f68c3b78541 in g_thread_pool_thread_proxy ../../../glib/gthreadpool.c:336
    #9 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #10 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #11 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b30554 in g_hash_table_maybe_make_big_keys_or_values ../../../glib/ghash.c:880
    #3 0x7f68c3b30554 in g_hash_table_maybe_make_big_keys_or_values ../../../glib/ghash.c:872
    #4 0x7f68c3b30554 in g_hash_table_ensure_keyval_fits ../../../glib/ghash.c:939
    #5 0x7f68c3b30554 in g_hash_table_insert_node ../../../glib/ghash.c:1298
    #6 0x7f68c3b30d45 in g_hash_table_insert_internal ../../../glib/ghash.c:1572
    #7 0x7f68c3b30d45 in g_hash_table_insert ../../../glib/ghash.c:1601
    #8 0x7f689be2eaef in janus_videoroom_handler plugins/janus_videoroom.c:9639
    #9 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #10 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #11 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7f68c3efc778 in realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:85
    #1 0x7f68c3b4a849 in g_realloc ../../../glib/gmem.c:171
    #2 0x7f68c3b2b3e7 in g_hash_table_realloc_key_or_value_array ../../../glib/ghash.c:324
    #3 0x7f68c3b2b3e7 in g_hash_table_setup_storage ../../../glib/ghash.c:534
    #4 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #5 0x7f689bdbb988 in janus_videoroom_process_synchronous_request plugins/janus_videoroom.c:7829
    #6 0x7f689bddd3f0 in janus_videoroom_handle_message plugins/janus_videoroom.c:8269
    #7 0x55ae9fd7b933 in janus_process_incoming_request /home/atoppi/src/janus-gateway/src/janus.c:1826
    #8 0x55ae9fdab61b in janus_transport_task /home/atoppi/src/janus-gateway/src/janus.c:3550
    #9 0x7f68c3b78541 in g_thread_pool_thread_proxy ../../../glib/gthreadpool.c:336
    #10 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #11 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #12 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b303ea in g_hash_table_maybe_make_big_keys_or_values ../../../glib/ghash.c:880
    #3 0x7f68c3b303ea in g_hash_table_maybe_make_big_keys_or_values ../../../glib/ghash.c:872
    #4 0x7f68c3b303ea in g_hash_table_ensure_keyval_fits ../../../glib/ghash.c:927
    #5 0x7f68c3b303ea in g_hash_table_insert_node ../../../glib/ghash.c:1298
    #6 0x7f68c3b30d45 in g_hash_table_insert_internal ../../../glib/ghash.c:1572
    #7 0x7f68c3b30d45 in g_hash_table_insert ../../../glib/ghash.c:1601
    #8 0x7f689be2eaef in janus_videoroom_handler plugins/janus_videoroom.c:9639
    #9 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #10 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #11 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efc778 in realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:85
    #1 0x7f68c3b4a849 in g_realloc ../../../glib/gmem.c:171
    #2 0x7f68c3b2b3e7 in g_hash_table_realloc_key_or_value_array ../../../glib/ghash.c:324
    #3 0x7f68c3b2b3e7 in g_hash_table_setup_storage ../../../glib/ghash.c:534
    #4 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #5 0x7f689bcc02ce in janus_videoroom_init plugins/janus_videoroom.c:3951
    #6 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #7 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #8 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #9 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f68c3b2b3fc in g_hash_table_setup_storage ../../../glib/ghash.c:536
    #3 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #4 0x7f689bcc0224 in janus_videoroom_init plugins/janus_videoroom.c:3949
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f68c3b2b3fc in g_hash_table_setup_storage ../../../glib/ghash.c:536
    #3 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #4 0x7f689bcc043f in janus_videoroom_init plugins/janus_videoroom.c:3953
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efc778 in realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:85
    #1 0x7f68c3b4a849 in g_realloc ../../../glib/gmem.c:171
    #2 0x7f68c3b2b3e7 in g_hash_table_realloc_key_or_value_array ../../../glib/ghash.c:324
    #3 0x7f68c3b2b3e7 in g_hash_table_setup_storage ../../../glib/ghash.c:534
    #4 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #5 0x7f689bcc043f in janus_videoroom_init plugins/janus_videoroom.c:3953
    #6 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #7 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #8 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #9 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f68c3b4a7a1 in g_malloc0 ../../../glib/gmem.c:133
    #2 0x7f68c3b2b3fc in g_hash_table_setup_storage ../../../glib/ghash.c:536
    #3 0x7f68c3b2b482 in g_hash_table_new_full ../../../glib/ghash.c:1028
    #4 0x7f689bcc02ce in janus_videoroom_init plugins/janus_videoroom.c:3951
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b5f4c8 in g_strdup ../../../glib/gstrfuncs.c:323
    #3 0x7f689bcbf7c5 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321
    #4 0x7f689bcbf7c5 in janus_videoroom_init plugins/janus_videoroom.c:3936
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 15 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b5f4c8 in g_strdup ../../../glib/gstrfuncs.c:323
    #3 0x7f689bcb7aa7 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321
    #4 0x7f689bcb7aa7 in janus_videoroom_init plugins/janus_videoroom.c:3778
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 9 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b5f4c8 in g_strdup ../../../glib/gstrfuncs.c:323
    #3 0x7f689bcb7d08 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321
    #4 0x7f689bcb7d08 in janus_videoroom_init plugins/janus_videoroom.c:3783
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b5f4c8 in g_strdup ../../../glib/gstrfuncs.c:323
    #3 0x7f689bcb7838 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321
    #4 0x7f689bcb7838 in janus_videoroom_init plugins/janus_videoroom.c:3775
    #5 0x55ae9fdfb083 in main /home/atoppi/src/janus-gateway/src/janus.c:5752
    #6 0x7f68c282a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7f68c282a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55ae9fc32734 in _start (/usr/local/janus/bin/janus+0x2ec734) (BuildId: a8b44eb20e0443385d5970e3a0fcc05ff70c999f)

Indirect leak of 4 byte(s) in 2 object(s) allocated from:
    #0 0x7f68c3efd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f68c3b49af9 in g_malloc ../../../glib/gmem.c:100
    #2 0x7f68c3b5f4c8 in g_strdup ../../../glib/gstrfuncs.c:323
    #3 0x7f689bdb80a7 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321
    #4 0x7f689bdb80a7 in janus_videoroom_process_synchronous_request plugins/janus_videoroom.c:7742
    #5 0x7f689bddd3f0 in janus_videoroom_handle_message plugins/janus_videoroom.c:8269
    #6 0x55ae9fd7b933 in janus_process_incoming_request /home/atoppi/src/janus-gateway/src/janus.c:1826
    #7 0x55ae9fdab61b in janus_transport_task /home/atoppi/src/janus-gateway/src/janus.c:3550
    #8 0x7f68c3b78541 in g_thread_pool_thread_proxy ../../../glib/gthreadpool.c:336
    #9 0x7f68c3b72c81 in g_thread_proxy ../../../glib/gthread.c:835
    #10 0x7f68c3e5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #11 0x7f68c289ca93 in start_thread nptl/pthread_create.c:447

SUMMARY: AddressSanitizer: 2425 byte(s) leaked in 27 allocation(s).

@atoppi
Copy link
Member

atoppi commented Nov 5, 2024

adding the refcount debug output
https://pastebin.com/Zq4QPLcn

@fancycode
Copy link
Contributor Author

Adding the report from ASan (commit 51fe38a)

Just to be sure, you are testing the current master branch and not this PR, right?

@atoppi
Copy link
Member

atoppi commented Nov 5, 2024

@fancycode yes, I mentioned the commit hash, it's from current master.
I'm adding some context to validate the proposed patch.

@fancycode
Copy link
Contributor Author

@fancycode yes, I mentioned the commit hash, it's from current master. I'm adding some context to validate the proposed patch.

Ok, perfect :-) Thanks for confirming.

@atoppi
Copy link
Member

atoppi commented Nov 5, 2024

@fancycode We prepared a patch according to the issues reported by ASan, UBSan and ref counting.
It partially overlaps with yours but avoid the explicit call janus_videoroom_session_destroy.

Can you try the attached diff and report? (on top of current master).

git apply fix_remote_publisher_leak.txt

fix_remote_publisher_leak.txt

@atoppi
Copy link
Member

atoppi commented Nov 6, 2024

We started tracking an alternative patch in #3475.
I was not able to replicate any leak or crashes.

@fancycode could you give that a try?

@fancycode
Copy link
Contributor Author

We started tracking an alternative patch in #3475. I was not able to replicate any leak or crashes.

Thanks!

@fancycode could you give that a try?

Not yet, I hope to have feedback sometime the next days.

@lminiero
Copy link
Member

lminiero commented Nov 6, 2024

Mentioning @spscream too, since they started using remote publishers extensively I think.

@spscream
Copy link
Contributor

spscream commented Nov 6, 2024

@lminiero we don't pushed remote publishers to production yet, we will start use it in production under load within weeks. Anyway if any crashes or leaks will appear on dev/staging I'll let you know.

@fancycode
Copy link
Contributor Author

Not yet, I hope to have feedback sometime the next days.

I did some tests with #3475 and could no longer reproduce the leaks I had before. Thanks!

@fancycode
Copy link
Contributor Author

Superseeded by #3475

@fancycode fancycode closed this Nov 7, 2024
@fancycode fancycode deleted the destroy-forwarders branch November 18, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants