Pārlūkot izejas kodu

Catch uncaught exceptions from incoming media handler chain

Paul-Louis Ageneau 9 mēneši atpakaļ
vecāks
revīzija
933364a722
2 mainītis faili ar 23 papildinājumiem un 11 dzēšanām
  1. 10 5
      src/impl/peerconnection.cpp
  2. 13 6
      src/impl/track.cpp

+ 10 - 5
src/impl/peerconnection.cpp

@@ -538,11 +538,16 @@ void PeerConnection::forwardMedia([[maybe_unused]] message_ptr message) {
 	if (auto handler = getMediaHandler()) {
 		message_vector messages{std::move(message)};
 
-		handler->incoming(messages, [this](message_ptr message) {
-			auto transport = std::atomic_load(&mDtlsTransport);
-			if (auto srtpTransport = std::dynamic_pointer_cast<DtlsSrtpTransport>(transport))
-				srtpTransport->send(std::move(message));
-		});
+		try {
+			handler->incomingChain(messages, [this](message_ptr message) {
+				auto transport = std::atomic_load(&mDtlsTransport);
+				if (auto srtpTransport = std::dynamic_pointer_cast<DtlsSrtpTransport>(transport))
+					srtpTransport->send(std::move(message));
+			});
+		} catch(const std::exception &e) {
+			PLOG_WARNING << "Exception in global incoming media handler: " << e.what();
+			return;
+		}
 
 		for (auto &m : messages)
 			dispatchMedia(std::move(m));

+ 13 - 6
src/impl/track.cpp

@@ -141,12 +141,18 @@ void Track::incoming(message_ptr message) {
 	}
 
 	message_vector messages{std::move(message)};
-	if (auto handler = getMediaHandler())
-		handler->incomingChain(messages, [this, weak_this = weak_from_this()](message_ptr m) {
-			if (auto locked = weak_this.lock()) {
-				transportSend(m);
-			}
-		});
+	if (auto handler = getMediaHandler()) {
+		try {
+			handler->incomingChain(messages, [this, weak_this = weak_from_this()](message_ptr m) {
+				if (auto locked = weak_this.lock()) {
+					transportSend(m);
+				}
+			});
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Exception in incoming media handler: " << e.what();
+			return;
+		}
+	}
 
 	for (auto &m : messages) {
 		// Tail drop if queue is full
@@ -184,6 +190,7 @@ bool Track::outgoing(message_ptr message) {
 				transportSend(m);
 			}
 		});
+
 		bool ret = false;
 		for (auto &m : messages)
 			ret = transportSend(std::move(m));