Skip to content

Commit

Permalink
Catch uncaught exceptions from incoming media handler chain
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Oct 23, 2024
1 parent 304e16c commit 933364a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/impl/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
19 changes: 13 additions & 6 deletions src/impl/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,6 +190,7 @@ bool Track::outgoing(message_ptr message) {
transportSend(m);
}
});

bool ret = false;
for (auto &m : messages)
ret = transportSend(std::move(m));
Expand Down

0 comments on commit 933364a

Please sign in to comment.