Skip to content

Commit

Permalink
[XrdCl] Check for closed connection between handling of read and writ…
Browse files Browse the repository at this point in the history
…e events
  • Loading branch information
smithdh authored and root committed Feb 27, 2023
1 parent 0d9f3a3 commit 516f724
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/XrdCl/XrdClAsyncSocketHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ namespace XrdCl
pHSWaitStarted( 0 ),
pHSWaitSeconds( 0 ),
pUrl( url ),
pTlsHandShakeOngoing( false )
pTlsHandShakeOngoing( false ),
pCloseCount( 0 )
{
Env *env = DefaultEnv::GetEnv();

Expand Down Expand Up @@ -190,6 +191,7 @@ namespace XrdCl

pPoller->RemoveSocket( pSocket );
pSocket->Close();
pCloseCount.fetch_add( 1, std::memory_order_relaxed );
return XRootDStatus();
}

Expand All @@ -213,6 +215,12 @@ namespace XrdCl
//--------------------------------------------------------------------------
type = pSocket->MapEvent( type );

//--------------------------------------------------------------------------
// In case we'll be handling both read and write events be prepared to
// detect a close between the handling of each.
//--------------------------------------------------------------------------
const uint32_t closeCount = pCloseCount.load( std::memory_order_relaxed );

//--------------------------------------------------------------------------
// Read event
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -241,6 +249,15 @@ namespace XrdCl
OnTimeoutWhileHandshaking();
}

//--------------------------------------------------------------------------
// We check to see if any of the read event handlers above may have caused
// us to be closed. If so, we may have been re-opened, added to another
// poller and now be concurrently handling requests for another connection.
// Discontinue processing if a close is detected.
//--------------------------------------------------------------------------
if( closeCount != pCloseCount.load( std::memory_order_relaxed ) )
return;

//--------------------------------------------------------------------------
// Write event
//--------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/XrdCl/XrdClAsyncSocketHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "XrdCl/XrdClAsyncMsgWriter.hh"
#include "XrdCl/XrdClAsyncHSWriter.hh"

#include <atomic>

namespace XrdCl
{
class Stream;
Expand Down Expand Up @@ -276,6 +278,8 @@ namespace XrdCl
std::unique_ptr<AsyncMsgReader> rspreader;
std::unique_ptr<AsyncHSReader> hsreader;
std::unique_ptr<AsyncMsgWriter> reqwriter;

std::atomic<uint32_t> pCloseCount;
};
}

Expand Down

0 comments on commit 516f724

Please sign in to comment.