Skip to content
Merged
12 changes: 10 additions & 2 deletions src/DebugConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ Syslog &Syslog::logMask(uint8_t priMask)

void Syslog::enable()
{
this->_client->begin(this->_port);
this->_enabled = true;
}

Expand Down Expand Up @@ -166,14 +165,21 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *appName, const char *mess
if ((pri & LOG_FACMASK) == 0)
pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri);

// W5100S: acquire UDP socket on-demand to avoid permanent socket consumption
if (!this->_client->begin(this->_port)) {
return false;
}

if (this->_server != NULL) {
result = this->_client->beginPacket(this->_server, this->_port);
} else {
result = this->_client->beginPacket(this->_ip, this->_port);
}
Comment thread
thebentern marked this conversation as resolved.

if (result != 1)
if (result != 1) {
this->_client->stop();
return false;
}

this->_client->print('<');
this->_client->print(pri);
Expand All @@ -193,6 +199,8 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *appName, const char *mess
this->_client->print(message);
this->_client->endPacket();
Comment thread
thebentern marked this conversation as resolved.

this->_client->stop(); // W5100S: release UDP socket for other services

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mesh/eth/ethClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static int32_t reconnectETH()

#ifndef DISABLE_NTP
LOG_INFO("Start NTP time client");
timeClient.begin();
timeClient.setUpdateInterval(60 * 60); // Update once an hour
#endif

Expand Down Expand Up @@ -96,6 +95,7 @@ static int32_t reconnectETH()
LOG_ERROR("NTP Update failed");
ntp_renew = millis() + 300 * 1000; // failure, retry every 5 minutes
}
timeClient.end(); // W5100S: release UDP socket for other services
}
#endif

Expand Down
6 changes: 5 additions & 1 deletion src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,11 @@ bool MQTT::isValidConfig(const meshtastic_ModuleConfig_MQTTConfig &config, MQTTC
}
std::unique_ptr<PubSubClient> pubSub(new PubSubClient);
if (isConnectedToNetwork()) {
return connectPubSub(parsed, *pubSub, (client != nullptr) ? *client : *clientConnection);
bool result = connectPubSub(parsed, *pubSub, (client != nullptr) ? *client : *clientConnection);
if (client == nullptr) {
pubSub->disconnect();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Socket cleanup is conditional on client == nullptr; when a non-null client is passed, successful validation can still leave the connection open. Since this function is a validator, that side effect can leak scarce sockets on Ethernet-class devices. Consider ensuring cleanup for all validation paths (or explicitly documenting and renaming if persistent connection is intended).

}
return result;
}
#else
const char *warning = "Invalid MQTT config: proxy_to_client_enabled must be enabled on nodes that do not have a network";
Expand Down
Loading