meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.17k stars 2.47k forks source link

[1.x] subscribe will get black screen when a publisher crash #3202

Closed nikohpng closed 1 year ago

nikohpng commented 1 year ago

Description

After joining the association, a client suddenly crashes and still needs to subscribe to a client that no longer exists, which will result in a direct black screen

Env

Log

[janus] [Fri Apr 21 17:36:05 2023] [WSS-0x7f4e5c003430] WS connection down, closing
[janus] [Fri Apr 21 17:36:05 2023] [WSS-0x7f4e5c003430] Destroying WebSocket client
[janus] [Fri Apr 21 17:36:05 2023] A janus.transport.websockets transport instance has gone away (0x7f4e5c015620)
[janus] [Fri Apr 21 17:36:05 2023]   -- Session 7355024178919153 will be over if not reclaimed
[janus] [Fri Apr 21 17:36:05 2023]   -- Marking Session 7355024178919153 as over 
[janus] [Fri Apr 21 17:36:05 2023] Destroying session 7355024178919153; 0x7f4e58002670[janus] [Fri Apr 21 17:36:05 2023] [7572160982336883] Hanging up PeerConnection because of a Detach
[janus] [Fri Apr 21 17:36:05 2023] [7572160982336883] Manually removed handle from loop #3 
[janus] [Fri Apr 21 17:36:05 2023] Detaching handle from JANUS VideoRoom plugin; 0x7f4e5800c010 0x7f4e5800cf50 0x7f4e5800c010 0x7f4e58009d00
[janus] [Fri Apr 21 17:36:05 2023] [7572160982336883] Handle detached, scheduling destruction
[janus] [Fri Apr 21 17:36:05 2023] [6232629127268866] Hanging up PeerConnection because of a Detach[janus] [Fri Apr 21 17:36:05 2023] [6232629127268866] Manually removed handle from loop #1
[janus] [Fri Apr 21 17:36:05 2023] Detaching handle from JANUS VideoRoom plugin; 0x7f4e5800f3c0 0x7f4e58007df0 0x7f4e5800f3c0 0x7f4e58012b90
[janus] [Fri Apr 21 17:36:05 2023] [6232629127268866] Handle detached, scheduling destruction
[janus] [Fri Apr 21 17:36:05 2023] [WSS-0x7f4e5c003430]   -- closed
[janus] [Fri Apr 21 17:36:05 2023] [7572160982336883] DTLS alert triggered on stream 1 (component 1), closing...
[janus] [Fri Apr 21 17:36:05 2023] [7572160982336883] Telling the plugin about the hangup (JANUS VideoRoom plugin)

...

[janus] [Fri Apr 21 17:36:05 2023] Configuring new participant
[janus] [Fri Apr 21 17:36:05 2023] Configuring new subscriber
[janus] [Fri Apr 21 17:36:05 2023] [ERR] [plugins/janus_videoroom.c:janus_videoroom_handler:11085] No such feed (10298)

Souce

L9677

 // janus_videoroom.c
  janus_videoroom_publisher *publisher = g_hash_table_lookup(videoroom->participants,
                                                             string_ids ? (gpointer) feed_id_str
                                                             : (gpointer) &feed_id);
  if (publisher == NULL || g_atomic_int_get(&publisher->destroyed) ||
  !g_atomic_int_get(&publisher->session->started)) {
      JANUS_LOG(LOG_ERR, "No such feed (%s)\n", feed_id_str);
      error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_FEED;
      g_snprintf(error_cause, 512, "No such feed (%s)", feed_id_str);
      janus_mutex_unlock(&videoroom->mutex);
      /* Unref publishers we may have taken note of so far */
      while (publishers) {
          publisher = (janus_videoroom_publisher *) publishers->data;
          janus_refcount_decrease(&publisher->session->ref);
          janus_refcount_decrease(&publisher->ref);
          publishers = g_list_remove(publishers, publisher);
      }
      janus_refcount_decrease(&videoroom->ref);
      goto error;
  }

Question

Do we need to continue subscribing even if the user no longer exists when subscribing?

lminiero commented 1 year ago

By default (the feature can be disabled), the VideoRoom will send subscribers a new offer automatically, unsubscribing from publishers that left, but that will only happen once Janus realizes the publisher has gone. Since you mention a crash, there was no explicit teardown from the publisher, and so you may have to wait for the session timeout to kick in.

Not an issue, so I'll close this. Please use the group for usage questions like this.