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

[Server] Avoid a race condition during deferred file close #1907

Merged
merged 1 commit into from
Feb 15, 2023
Merged
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
13 changes: 12 additions & 1 deletion src/XrdXrootd/XrdXrootdXeq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,24 @@ int XrdXrootdProtocol::do_Close()
fp->cbArg = ReqID.getID();
fp->XrdSfsp->error.setErrCB(&closeCB, (unsigned long long)fp);

// Add a reference count to the file in case the close will be deferred. In
// the deferred case the reference is used to prevent the callback from
// deleting the file until we have done necessary processing of the object
// during its removal from the open table.
//
fp->Ref(1);

// Do an explicit close of the file here; check for exceptions. Stall requests
// leave the file open as there will be a retry. Otherwise, we remove the
// file from our open table but a "started" return defers the the delete.
//
rc = fp->XrdSfsp->close();
TRACEP(FS, " fh=" <<fh.handle <<" close rc=" <<rc);
if (rc >= SFS_STALL) return fsError(rc, 0, fp->XrdSfsp->error, 0, 0);
if (rc == SFS_STARTED) doDel = false;
else {fp->Ref(-1);
if (rc >= SFS_STALL)
return fsError(rc, 0, fp->XrdSfsp->error, 0, 0);
}

// Before we potentially delete the file handle in FTab->Del, generate the
// appropriate error code (if necessary). Note that we delay the call
Expand All @@ -579,6 +589,7 @@ int XrdXrootdProtocol::do_Close()
//
FTab->Del((Monitor.Files() ? Monitor.Agent : 0), fh.handle, doDel);
numFiles--;
if (!doDel) fp->Ref(-1);

// Send back the right response
//
Expand Down