Fix satellite heartbeat timeout cleanup and /status blocking
Heartbeat timeout called m_con->disconnect() on a server-managed connection, which didn't trigger TcpServer::clientDisconnected — leaving dead satellites in the map forever. After timeout, the unsigned rx counter wrapped to UINT_MAX preventing re-detection. The timer also kept firing sendMsg() to the dead socket, blocking the event loop and causing /status to stall for ~10s. Fix: SatelliteLink emits linkFailed signal instead of calling disconnect directly. Reflector handles cleanup via a deferred zero-timer to avoid re-entrancy. The /status handler skips satellites pending cleanup. Also disable ALSA in Docker build (unused by the reflector).
This commit is contained in:
1 parent
195be03036
commit
fa57db6e62
5 files changed
+71
-4
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
|
||||
WORKDIR /src
|
||||
COPY src/ src/
|
||||
RUN cmake -S src -B build -DLOCAL_STATE_DIR=/var \
|
||||
RUN cmake -S src -B build -DLOCAL_STATE_DIR=/var -DUSE_ALSA=OFF \
|
||||
&& cmake --build build
|
||||
|
||||
|
||||
|
||||
@@ -242,7 +242,8 @@ Reflector::Reflector(void)
|
||||
: m_srv(0), m_udp_sock(0), m_tg_for_v1_clients(1), m_random_qsy_lo(0),
|
||||
m_random_qsy_hi(0), m_random_qsy_tg(0), m_http_server(0), m_cmd_pty(0),
|
||||
m_keys_dir("private/"), m_pending_csrs_dir("pending_csrs/"),
|
||||
m_csrs_dir("csrs/"), m_certs_dir("certs/"), m_pki_dir("pki/")
|
||||
m_csrs_dir("csrs/"), m_certs_dir("certs/"), m_pki_dir("pki/"),
|
||||
m_sat_cleanup_timer(0, Async::Timer::TYPE_ONESHOT)
|
||||
{
|
||||
TGHandler::instance()->talkerUpdated.connect(
|
||||
mem_fun(*this, &Reflector::onTalkerUpdated));
|
||||
@@ -268,6 +269,9 @@ Reflector::Reflector(void)
|
||||
<< std::endl;
|
||||
}
|
||||
});
|
||||
m_sat_cleanup_timer.setEnable(false);
|
||||
m_sat_cleanup_timer.expired.connect(
|
||||
sigc::mem_fun(*this, &Reflector::processSatelliteCleanup));
|
||||
m_status["nodes"] = Json::Value(Json::objectValue);
|
||||
} /* Reflector::Reflector */
|
||||
|
||||
@@ -1646,19 +1650,32 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
||||
}
|
||||
m_status["cluster_tgs"] = cluster_arr;
|
||||
|
||||
if (!m_satellite_con_map.empty())
|
||||
{
|
||||
Json::Value sats(Json::objectValue);
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
auto* sat = kv.second;
|
||||
// Skip satellites pending cleanup (heartbeat timed out)
|
||||
if (std::find(m_sat_cleanup_pending.begin(),
|
||||
m_sat_cleanup_pending.end(),
|
||||
sat) != m_sat_cleanup_pending.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!sat->satelliteId().empty())
|
||||
{
|
||||
sats[sat->satelliteId()] = sat->statusJson();
|
||||
}
|
||||
}
|
||||
if (sats.empty())
|
||||
{
|
||||
m_status.removeMember("satellites");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_status["satellites"] = sats;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
Json::StreamWriterBuilder builder;
|
||||
@@ -2060,6 +2077,8 @@ void Reflector::satelliteConnected(Async::FramedTcpConnection* con)
|
||||
std::cout << "SAT: Inbound connection from "
|
||||
<< con->remoteHost() << ":" << con->remotePort() << std::endl;
|
||||
auto* link = new SatelliteLink(this, con, m_satellite_secret);
|
||||
link->linkFailed.connect(
|
||||
sigc::mem_fun(*this, &Reflector::onSatelliteLinkFailed));
|
||||
m_satellite_con_map[con] = link;
|
||||
} /* Reflector::satelliteConnected */
|
||||
|
||||
@@ -2078,6 +2097,42 @@ void Reflector::satelliteDisconnected(Async::FramedTcpConnection* con,
|
||||
} /* Reflector::satelliteDisconnected */
|
||||
|
||||
|
||||
void Reflector::onSatelliteLinkFailed(SatelliteLink* link)
|
||||
{
|
||||
m_sat_cleanup_pending.push_back(link);
|
||||
m_sat_cleanup_timer.setEnable(false);
|
||||
m_sat_cleanup_timer.setTimeout(0);
|
||||
m_sat_cleanup_timer.setEnable(true);
|
||||
} /* Reflector::onSatelliteLinkFailed */
|
||||
|
||||
|
||||
void Reflector::processSatelliteCleanup(Async::Timer* t)
|
||||
{
|
||||
std::vector<SatelliteLink*> pending;
|
||||
pending.swap(m_sat_cleanup_pending);
|
||||
|
||||
for (SatelliteLink* link : pending)
|
||||
{
|
||||
Async::FramedTcpConnection* con = nullptr;
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
if (kv.second == link)
|
||||
{
|
||||
con = kv.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (con == nullptr) continue;
|
||||
|
||||
std::cout << "SAT: Cleaning up timed-out satellite '"
|
||||
<< link->satelliteId() << "'" << std::endl;
|
||||
delete link;
|
||||
m_satellite_con_map.erase(con);
|
||||
con->disconnect();
|
||||
}
|
||||
} /* Reflector::processSatelliteCleanup */
|
||||
|
||||
|
||||
void Reflector::forwardSatelliteAudioToTrunks(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
|
||||
@@ -306,6 +306,8 @@ class Reflector : public sigc::trackable
|
||||
FramedTcpServer* m_sat_srv = nullptr;
|
||||
std::string m_satellite_secret;
|
||||
std::map<Async::FramedTcpConnection*, SatelliteLink*> m_satellite_con_map;
|
||||
std::vector<SatelliteLink*> m_sat_cleanup_pending;
|
||||
Async::Timer m_sat_cleanup_timer;
|
||||
|
||||
Reflector(const Reflector&);
|
||||
Reflector& operator=(const Reflector&);
|
||||
@@ -334,6 +336,8 @@ class Reflector : public sigc::trackable
|
||||
void satelliteConnected(Async::FramedTcpConnection* con);
|
||||
void satelliteDisconnected(Async::FramedTcpConnection* con,
|
||||
Async::FramedTcpConnection::DisconnectReason reason);
|
||||
void onSatelliteLinkFailed(SatelliteLink* link);
|
||||
void processSatelliteCleanup(Async::Timer* t);
|
||||
bool loadCertificateFiles(void);
|
||||
bool loadServerCertificateFiles(void);
|
||||
bool generateKeyFile(Async::SslKeypair& pkey, const std::string& keyfile);
|
||||
|
||||
@@ -280,6 +280,7 @@ void SatelliteLink::heartbeatTick(Async::Timer* t)
|
||||
{
|
||||
cerr << "*** ERROR[SAT '" << m_satellite_id
|
||||
<< "']: Heartbeat timeout — disconnecting" << endl;
|
||||
m_con->disconnect();
|
||||
m_heartbeat_timer.setEnable(false);
|
||||
linkFailed(this);
|
||||
}
|
||||
} /* SatelliteLink::heartbeatTick */
|
||||
@@ -30,6 +30,13 @@ class SatelliteLink : public sigc::trackable
|
||||
const std::string& satelliteId(void) const { return m_satellite_id; }
|
||||
Json::Value statusJson(void) const;
|
||||
|
||||
/**
|
||||
* Emitted when the satellite link has failed (heartbeat timeout).
|
||||
* The Reflector must handle cleanup — the SatelliteLink stops its own
|
||||
* timer but does NOT call m_con->disconnect() itself.
|
||||
*/
|
||||
sigc::signal<void, SatelliteLink*> linkFailed;
|
||||
|
||||
// Events from local clients or trunk peers → send down to satellite
|
||||
void onParentTalkerStart(uint32_t tg, const std::string& callsign);
|
||||
void onParentTalkerStop(uint32_t tg);
|
||||
|
||||
Reference in new issue
Block a user