Skip to content

Commit

Permalink
[XrdCl] Avoid segv caused by reconnect vs force disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Mar 29, 2023
1 parent c91b1ac commit eae57b4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/XrdCl/XrdClChannel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ namespace XrdCl
return Status();
}

//----------------------------------------------------------------------------
// Force reconnect
//----------------------------------------------------------------------------
Status Channel::ForceReconnect()
{
pStream->ForceConnect();
return Status();
}

//------------------------------------------------------------------------
// Get the number of connected data streams
//------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/XrdCl/XrdClChannel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ namespace XrdCl
//------------------------------------------------------------------------
Status ForceDisconnect();

//------------------------------------------------------------------------
//! Force reconnect
//------------------------------------------------------------------------
Status ForceReconnect();

//------------------------------------------------------------------------
//! Get the number of connected data streams
//------------------------------------------------------------------------
Expand Down
19 changes: 18 additions & 1 deletion src/XrdCl/XrdClPostMaster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ namespace XrdCl
AnyObject &result )
{
XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock );
Channel *channel = GetChannel( url );
PostMasterImpl::ChannelMap::iterator it =
pImpl->pChannelMap.find( url.GetChannelId() );
if( it == pImpl->pChannelMap.end() )
return Status( stError, errInvalidOp );
Channel *channel = it->second;

if( !channel )
return Status( stError, errNotSupported );
Expand Down Expand Up @@ -320,6 +324,19 @@ namespace XrdCl
return Status();
}

Status PostMaster::ForceReconnect( const URL &url )
{
XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false );
PostMasterImpl::ChannelMap::iterator it =
pImpl->pChannelMap.find( url.GetChannelId() );

if( it == pImpl->pChannelMap.end() )
return Status( stError, errInvalidOp );

it->second->ForceReconnect();
return Status();
}

//------------------------------------------------------------------------
// Get the number of connected data streams
//------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/XrdCl/XrdClPostMaster.hh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ namespace XrdCl
//------------------------------------------------------------------------
Status ForceDisconnect( const URL &url );

//------------------------------------------------------------------------
//! Reconnect the channel
//------------------------------------------------------------------------
Status ForceReconnect( const URL &url );

//------------------------------------------------------------------------
//! Get the number of connected data streams
//------------------------------------------------------------------------
Expand Down
25 changes: 14 additions & 11 deletions src/XrdCl/XrdClStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,14 @@ namespace XrdCl
void Stream::ForceConnect()
{
XrdSysMutexHelper scopedLock( pMutex );
pSubStreams[0]->status = Socket::Disconnected;
XrdCl::PathID path( 0, 0 );
XrdCl::XRootDStatus st = EnableLink( path );
if( !st.IsOK() )
OnConnectError( 0, st );
if( pSubStreams[0]->status == Socket::Connecting )
{
pSubStreams[0]->status = Socket::Disconnected;
XrdCl::PathID path( 0, 0 );
XrdCl::XRootDStatus st = EnableLink( path );
if( !st.IsOK() )
OnConnectError( 0, st );
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -399,11 +402,11 @@ namespace
//------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------
StreamConnectorTask( XrdCl::Stream *stream ):
pStream( stream )
StreamConnectorTask( const XrdCl::URL &url, const std::string &n ):
url( url )
{
std::string name = "StreamConnectorTask for ";
name += stream->GetName();
name += n;
SetName( name );
}

Expand All @@ -412,12 +415,12 @@ namespace
//------------------------------------------------------------------------
time_t Run( time_t )
{
pStream->ForceConnect();
XrdCl::DefaultEnv::GetPostMaster()->ForceReconnect( url );
return 0;
}

private:
XrdCl::Stream *pStream;
XrdCl::URL url;
};
}

Expand Down Expand Up @@ -775,7 +778,7 @@ namespace XrdCl
log->Info( PostMasterMsg, "[%s] Attempting reconnection in %d "
"seconds.", pStreamName.c_str(), pConnectionWindow-elapsed );

Task *task = new ::StreamConnectorTask( this );
Task *task = new ::StreamConnectorTask( *pUrl, pStreamName );
pTaskManager->RegisterTask( task, pConnectionInitTime+pConnectionWindow );
return;
}
Expand Down

0 comments on commit eae57b4

Please sign in to comment.