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
5 changes: 5 additions & 0 deletions src/mtconnect/source/adapter/agent_adapter/session_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ namespace mtconnect::source::adapter::agent_adapter {
LOG(error) << "Agent Adapter Target: " << m_request->getTarget(m_url);
LOG(error) << "Agent Adapter " << what << ": " << ec.message() << "\n";
m_request.reset();

// Clear cached DNS resolution so hostname is re-resolved on reconnect.
// This handles DHCP environments where IP addresses may change.
m_resolution.reset();

if (m_failed)
m_failed(ec);
}
Expand Down
16 changes: 15 additions & 1 deletion src/mtconnect/source/adapter/shdr/connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,21 @@ namespace mtconnect::source::adapter::shdr {
if (ec != boost::asio::error::operation_aborted)
{
LOG(info) << "reconnect: retrying connection";
asio::dispatch(m_strand, boost::bind(&Connector::connect, this));
// Re-resolve hostname to handle DHCP/dynamic IP environments.
// If the server is a hostname (not a static IP), re-resolve to get
// the current IP address in case it has changed.
boost::system::error_code parseEc;
asio::ip::address::from_string(m_server, parseEc);
if (parseEc)
{
// m_server is a hostname, re-resolve it
asio::dispatch(m_strand, boost::bind(&Connector::resolve, this));
}
else
{
// m_server is a static IP address, just reconnect
asio::dispatch(m_strand, boost::bind(&Connector::connect, this));
}
}
});
}
Expand Down