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 28, 2023
1 parent 0d9f3a3 commit 5e90d67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/XrdCl/XrdClAsyncSocketHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace XrdCl
pStreamName( ToStreamName( url, subStreamNum ) ),
pSocket( new Socket() ),
pHandShakeDone( false ),
pCloseCount( 0 ),
pConnectionStarted( 0 ),
pConnectionTimeout( 0 ),
pHSWaitStarted( 0 ),
Expand Down Expand Up @@ -190,6 +191,7 @@ namespace XrdCl

pPoller->RemoveSocket( pSocket );
pSocket->Close();
pCloseCount++;
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;

//--------------------------------------------------------------------------
// 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 )
return;

//--------------------------------------------------------------------------
// Write event
//--------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/XrdCl/XrdClAsyncSocketHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "XrdCl/XrdClAsyncHSReader.hh"
#include "XrdCl/XrdClAsyncMsgWriter.hh"
#include "XrdCl/XrdClAsyncHSWriter.hh"
#include "XrdSys/XrdSysRAtomic.hh"

namespace XrdCl
{
Expand Down Expand Up @@ -264,6 +265,7 @@ namespace XrdCl
std::unique_ptr<HandShakeData> pHandShakeData;
bool pHandShakeDone;
uint16_t pTimeoutResolution;
RAtomic_uint32_t pCloseCount;
time_t pConnectionStarted;
time_t pConnectionTimeout;
time_t pLastActivity;
Expand Down

0 comments on commit 5e90d67

Please sign in to comment.