Skip to content

Commit

Permalink
do not release all name server connections if channel search was unsu…
Browse files Browse the repository at this point in the history
…ccessful
  • Loading branch information
sveseli committed May 29, 2024
1 parent 7a64947 commit bb5fce6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
20 changes: 17 additions & 3 deletions src/remote/channelSearchManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,28 @@ void ChannelSearchManager::searchResponse(const ServerGUID & guid, pvAccessID ci
if(si)
si->searchResponse(guid, minorRevision, serverAddress);
}
// Release all NS connections if there are
// no more channels to search for
releaseNameServerTransport();
}

void ChannelSearchManager::releaseNameServerTransport(bool forceRelease)
{
if(m_channels.size() == 0 || forceRelease)
bool releaseAllConnections = true;
if(m_channels.size() == 0)
{
// No more channels to search for, release all connections
m_nsSearchCounter = 0;
m_context.lock()->releaseNameServerSearchTransport(m_nsTransport);
m_context.lock()->releaseNameServerSearchTransport(m_nsTransport, releaseAllConnections);
m_nsTransport.reset();
}
else if(forceRelease)
{
// There are channels to search for, release only connection
// that is currently used
releaseAllConnections = false;
m_nsSearchCounter = 0;
m_context.lock()->releaseNameServerSearchTransport(m_nsTransport, releaseAllConnections);
m_nsTransport.reset();
}
}
Expand Down Expand Up @@ -306,7 +319,8 @@ void ChannelSearchManager::flushSendBuffer()
// Name server transport
if(m_nsTransport)
{
// Reset transport after max. number of attempts is reached.
// Reset transport (current connection only)
// after max. number of attempts is reached.
if (m_nsSearchCounter >= MAX_NAME_SERVER_SEARCH_COUNT)
{
LOG(logLevelDebug, "Resetting name server transport after %d search attempts", m_nsSearchCounter);
Expand Down
2 changes: 1 addition & 1 deletion src/remote/pv/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class Context {
virtual std::tr1::shared_ptr<Channel> getChannel(pvAccessID id) = 0;
virtual Transport::shared_pointer getSearchTransport() = 0;
virtual Transport::shared_pointer getNameServerSearchTransport() {return Transport::shared_pointer();}
virtual void releaseNameServerSearchTransport(const Transport::shared_pointer& nsTransport = Transport::shared_pointer()) {}
virtual void releaseNameServerSearchTransport(const Transport::shared_pointer& nsTransport=Transport::shared_pointer(), bool releaseAllConnections=true) {}
};

/**
Expand Down
20 changes: 13 additions & 7 deletions src/remoteClient/clientContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,8 +2610,9 @@ class SearchResponseHandler : public AbstractClientResponseHandler {
{
if (transport->getType() == "tcp")
{
LOG(logLevelDebug, "No channels found, releasing name server transport");
csm->releaseNameServerTransport();
// Release only current NS connection
LOG(logLevelDebug, "No channels found, releasing current name server transport");
csm->releaseNameServerTransport(true);
}
return;
}
Expand Down Expand Up @@ -4183,7 +4184,7 @@ class InternalClientContextImpl :
return nsTransport;
}

virtual void releaseNameServerSearchTransport(const Transport::shared_pointer& nsTransport = Transport::shared_pointer())
virtual void releaseNameServerSearchTransport(const Transport::shared_pointer& nsTransport=Transport::shared_pointer(), bool releaseAllConnections=true)
{
if (nsTransport)
{
Expand All @@ -4200,10 +4201,15 @@ class InternalClientContextImpl :
Transport::shared_pointer nst = it->second;
if (!nst->isUsed())
{
LOG(logLevelDebug, "Closing name server transport for address %s", m_nsTransportConnectCallbackMap[i]->getNsAddress().c_str());
nst->close();
nst.reset();
m_nsTransportMap.erase(it);
// Release unused given connection only, unless
// other connections are no longer needed
if (nst == nsTransport || releaseAllConnections)
{
LOG(logLevelDebug, "Closing name server transport for address %s", m_nsTransportConnectCallbackMap[i]->getNsAddress().c_str());
nst->close();
nst.reset();
m_nsTransportMap.erase(it);
}
}
}
}
Expand Down

0 comments on commit bb5fce6

Please sign in to comment.