Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[nfs] - fix possible crash due to a race condition between context ti…

…meout and filehandle keepalive. This is related to / addition fix for #13505
  • Loading branch information...
commit 2896704f85c29b77533f1c653d3f63e1debcfcc0 1 parent ae04d99
@Memphiz Memphiz authored
Showing with 8 additions and 5 deletions.
  1. +7 −4 xbmc/filesystem/NFSFile.cpp
  2. +1 −1  xbmc/filesystem/NFSFile.h
11 xbmc/filesystem/NFSFile.cpp
@@ -140,7 +140,7 @@ void CNfsConnection::destroyOpenContexts()
-struct nfs_context *CNfsConnection::getContextFromMap(const CStdString &exportname)
+struct nfs_context *CNfsConnection::getContextFromMap(const CStdString &exportname, bool forceCacheHit/* = false*/)
struct nfs_context *pRet = NULL;
CSingleLock lock(openContextLock);
@@ -150,9 +150,9 @@ struct nfs_context *CNfsConnection::getContextFromMap(const CStdString &exportna
//check if context has timed out already
uint64_t now = XbmcThreads::SystemClockMillis();
- if((now - it->second.lastAccessedTime) < CONTEXT_TIMEOUT)
+ if((now - it->second.lastAccessedTime) < CONTEXT_TIMEOUT || forceCacheHit)
- //its not timedout yet
+ //its not timedout yet or caller wants the cached entry regardless of timeout
//refresh access time of that
//context and return it
CLog::Log(LOGDEBUG, "NFS: Refreshing context for %s, old: %"PRId64", new: %"PRId64, exportname.c_str(), it->second.lastAccessedTime, now);
@@ -383,7 +383,10 @@ void CNfsConnection::keepAlive(std::string _exportPath, struct nfsfh *_pFileHan
uint64_t offset = 0;
char buffer[32];
// this also refreshs the last accessed time for the context
- struct nfs_context *pContext = getContextFromMap(_exportPath);
+ // true forces a cachehit regardless the context is timedout
+ // on this call we are sure its not timedout even if the last accessed
+ // time suggests it.
+ struct nfs_context *pContext = getContextFromMap(_exportPath, true);
if (!pContext)// this should normally never happen - paranoia
pContext = m_pNfsContext;
2  xbmc/filesystem/NFSFile.h
@@ -114,7 +114,7 @@ class CNfsConnection : public CCriticalSection
CCriticalSection openContextLock;
void clearMembers();
- struct nfs_context *getContextFromMap(const CStdString &exportname);
+ struct nfs_context *getContextFromMap(const CStdString &exportname, bool forceCacheHit = false);
int getContextForExport(const CStdString &exportname);//get context for given export and add to open contexts map - sets m_pNfsContext (my return a already mounted cached context)
void destroyOpenContexts();
void resolveHost(const CURL &url);//resolve hostname by dnslookup
Please sign in to comment.
Something went wrong with that request. Please try again.