Skip to content

Commit 29653cb

Browse files
Merge pull request #1276 from paullouisageneau/exceptions-incoming-media-handler
Catch uncaught exceptions from incoming media handler chain
2 parents f786f5d + 933364a commit 29653cb

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/impl/peerconnection.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,16 @@ void PeerConnection::forwardMedia([[maybe_unused]] message_ptr message) {
538538
if (auto handler = getMediaHandler()) {
539539
message_vector messages{std::move(message)};
540540

541-
handler->incoming(messages, [this](message_ptr message) {
542-
auto transport = std::atomic_load(&mDtlsTransport);
543-
if (auto srtpTransport = std::dynamic_pointer_cast<DtlsSrtpTransport>(transport))
544-
srtpTransport->send(std::move(message));
545-
});
541+
try {
542+
handler->incomingChain(messages, [this](message_ptr message) {
543+
auto transport = std::atomic_load(&mDtlsTransport);
544+
if (auto srtpTransport = std::dynamic_pointer_cast<DtlsSrtpTransport>(transport))
545+
srtpTransport->send(std::move(message));
546+
});
547+
} catch(const std::exception &e) {
548+
PLOG_WARNING << "Exception in global incoming media handler: " << e.what();
549+
return;
550+
}
546551

547552
for (auto &m : messages)
548553
dispatchMedia(std::move(m));

src/impl/track.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,18 @@ void Track::incoming(message_ptr message) {
141141
}
142142

143143
message_vector messages{std::move(message)};
144-
if (auto handler = getMediaHandler())
145-
handler->incomingChain(messages, [this, weak_this = weak_from_this()](message_ptr m) {
146-
if (auto locked = weak_this.lock()) {
147-
transportSend(m);
148-
}
149-
});
144+
if (auto handler = getMediaHandler()) {
145+
try {
146+
handler->incomingChain(messages, [this, weak_this = weak_from_this()](message_ptr m) {
147+
if (auto locked = weak_this.lock()) {
148+
transportSend(m);
149+
}
150+
});
151+
} catch (const std::exception &e) {
152+
PLOG_WARNING << "Exception in incoming media handler: " << e.what();
153+
return;
154+
}
155+
}
150156

151157
for (auto &m : messages) {
152158
// Tail drop if queue is full
@@ -184,6 +190,7 @@ bool Track::outgoing(message_ptr message) {
184190
transportSend(m);
185191
}
186192
});
193+
187194
bool ret = false;
188195
for (auto &m : messages)
189196
ret = transportSend(std::move(m));

0 commit comments

Comments
 (0)