FileReader is not thread safe on Linux
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
DC++ |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
FileReader:
https:/
Since the function can be called concurrently from different threads (currently hashing/queue recheck/sfv check in DC++) and each of them sets and resets the SIGBUS handler, there's a high risk that the application will crash in case of read errors as they aren't being handler properly.
More information about the caveats: https:/
These issues are much more likely to happen with AirDC++ as it uses multiple threads for hashing. Read errors caused rather nasty crashes with corrupted stack traces for one user, but luckily he was able to catch the SIGBUS signal with gdb.
I didn't even spend time in trying to figure out how to make the mapped reads work properly, as based on my testing the basic FileReader:
readMapped: 671 files (21.70 GiB) in 9 directories have been hashed in 4 minutes 21 seconds (84.87 MiB/s)
readCached: 671 files (21.70 GiB) in 9 directories have been hashed in 3 minutes 58 seconds (93.08 MiB/s)
FileReader:
It looks in DC++ on Windows, the only supported DC++ platform, FileReader: :readMapped( ) already always fell through to FileReader: :readCached( ):
ret = readMapped(file, callback);
if(ret == READ_FAILED) {
dcdebug("Reading [full] %s\n", file.c_str());
ret = readCached(file, callback);
}
...
#ifdef _WIN32
...
size_t FileReader: :readMapped( const string& file, const DataCallback& callback) { /msdn.microsoft .com/en- us/library/ aa366801( VS.85). aspx> /stackoverflow. com/q/7244645> */
/** @todo mapped reads can fail on Windows by throwing an exception that may only be caught by
SEH. MinGW doesn't have that, thus making this method of reading prone to unrecoverable
failures. disabling this for now should be fine as DC++ always tries overlapped reads first
(at the moment this file reader is only used in places where overlapped reads make the most
sense).
more info:
<https:/
<https:/
#if 1
return READ_FAILED;
#else
...
#endif
}
#else
...
static sigjmp_buf sb_env;
static void sigbus_handler(int signum, siginfo_t* info, void* context) { sb_env, 1);
// Jump back to the readMapped which will return error. Apparently truncating
// a file in Solaris sets si_code to BUS_OBJERR
if (signum == SIGBUS && (info->si_code == BUS_ADRERR || info->si_code == BUS_OBJERR))
siglongjmp(
}
size_t FileReader: :readMapped( const string& filename, const DataCallback& callback) {
...
}
#endif
Had this also been the case in AirDC++ before you disabled FileReader: :readMapped( ) entirely, or were you only seeing reports of it from non-Windows systems, such as the Gentoo bug you linked?
Either way, it seems like a safe, reasonable, risk-averse change, since DC++ only targets Windows platforms currently, so at best there's a bunch of dead code in one platform-dependent preprocessor branch and some and very likely subtly incorrect code in the other platform-dependent branch. I'm inclined to remove FileReader: :readMapped( ), exactly as you suggest.