[TPC] Ensure file is closed prior to sending response to client #891
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the underlying OFS file handle was not closed until the destructor on the XrdTpcStream object was called - this occurs after the response was sent to a client.
In this case, subsequent operations may be done while the file is still open for writing, which may mean data has not been written out from the client cache to the distributed file system. If the subsequent operation (such as
stat
) is load-balanced to a different data server, then the second operation may observe an incomplete file.The fix is to explicitly cause the file handle to be closed prior to sending the response to the client. Then, as long as the filesystem has open-to-close consistency (which NFS and HDFS do have -- a much looser consistency requirement than POSIX), this should remove the possibility of reading an incomplete file.
This bug was revealed while testing load-balanced Xrootd on top of a HDFS filesystem at Nebraska. Depending on how often the race condition was triggered, it caused failure rates of up to 10%.