Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XrdCl] Check for closed connection between handling of read and write events #1935

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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