Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/MoqxPicoRelayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ MoqxPicoRelayServer::MoqxPicoRelayServer(
evb_(ioExecutor->getAllEventBases()[0].get()) {}

MoqxPicoRelayServer::~MoqxPicoRelayServer() {
stop();
}

void MoqxPicoRelayServer::stop() {
if (!context_) {
return;
}
context_->stop();
evb_->runImmediatelyOrRunInEventBaseThreadAndWait([this] { MoQPicoQuicEventBaseServer::stop(); });
context_.reset();
}

void MoqxPicoRelayServer::setStatsRegistry(std::shared_ptr<stats::StatsRegistry> registry) {
Expand Down
3 changes: 3 additions & 0 deletions src/MoqxPicoRelayServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class MoqxPicoRelayServer : public moxygen::MoQPicoQuicEventBaseServer {

~MoqxPicoRelayServer() override;

// Idempotent; safe to call from main and again from ~MoqxPicoRelayServer.
void stop() override;

void setStatsRegistry(std::shared_ptr<stats::StatsRegistry> registry);

// Preferred entry point: binds the address from the stored ListenerConfig.
Expand Down
9 changes: 9 additions & 0 deletions src/MoqxRelayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ MoqxRelayServer::MoqxRelayServer(

MoqxRelayServer::~MoqxRelayServer() {
// Close incoming connections, drain worker EVBs, then destroy EVBs.
stop();
}

void MoqxRelayServer::stop() {
if (!context_) {
return;
}
// QuicServer::shutdown drives terminateClientSession, which uses context_.
MoQServer::stop();
context_.reset();
}

void MoqxRelayServer::setStatsRegistry(std::shared_ptr<stats::StatsRegistry> registry) {
Expand Down
3 changes: 3 additions & 0 deletions src/MoqxRelayServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class MoqxRelayServer : public moxygen::MoQServer {

~MoqxRelayServer() override;

// Idempotent; safe to call from main and again from ~MoqxRelayServer.
void stop() override;

void setStatsRegistry(std::shared_ptr<stats::StatsRegistry> registry);

// Preferred entry point: binds the address from the stored ListenerConfig.
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ int main(int argc, char* argv[]) {
// Stop admin last — allows a final metrics scrape during drain.
adminServer.stop();

// Stop servers before joining the IO pool — stop() needs worker EVBs alive,
// and lingering shared_ptr refs could delay ~MoqxRelayServer past that point.
for (auto& server : servers) {
server->stop();
}
servers.clear();
ioExecutor.reset();

// === 14. Exit with appropriate code ===
return 0;
}
Loading