ASSIGNED 115761
Race condition with DatabaseTracker::deleteAllDatabases and web workers
https://bugs.webkit.org/show_bug.cgi?id=115761
Summary Race condition with DatabaseTracker::deleteAllDatabases and web workers
Chris Dalton
Reported 2013-05-07 14:52:56 PDT
When DatabaseTracker::deleteAllDatabases is called from the main thread, it ends up calling through DatabaseTracker::deleteDatabaseFile to Database::markAsDeletedAndClose, on all the relevant open databases (including those open by web workers). markAsDeletedAndClose first makes sure that databaseContext()->databaseThread()->terminationRequested() is false, and then schedules and waits for a DatabaseClose task. This has two problems: 1) It's possible for the worker thread to request termination AFTER markAsDeletedAndClose checks terminationRequested, but BEFORE it schedules and waits for the task. (WorkerThreadShutdownStartTask::performTask -> DatabaseManager::stopDatabases -> DatabaseContext::stopDatabases -> DatabaseThread::requestTermination.) In this scenario, the task will never execute and the main thread will hang. 2) It's possible for markAsDeletedAndClose to check terminationRequested AFTER the worker thread has requested termination, but BEFORE the database is fully closed. In this it's possible to delete the database file while a web worker still has it open. We need a thread-safe way of making sure all relevant databases are closed before deleting the file.
Attachments
Mark Lam
Comment 1 2013-05-07 23:28:06 PDT
Im already working on something in this area. Will investigate this issue as well.
Radar WebKit Bug Importer
Comment 3 2013-11-07 16:38:39 PST
Mark Lam
Comment 4 2013-11-07 16:40:42 PST
Brady Eidson
Comment 5 2013-11-07 16:46:30 PST
Tried to reproduce this multiple times with `run-webkit-tests fast/workers/storage -g -2` and `run-webkit-tests fast/workers/storage -2` to no avail. I think it's a strong possibility that the WAL journal_mode has made this race condition more likely to rear its ugly head.
Ahmad Saleem
Comment 6 2022-12-27 18:49:31 PST
Something similar was fixed in Blink: https://chromium.googlesource.com/chromium/blink/+/8462425975e2d8bc28b02d9c2416ddc9c8520aab It was about hang happening while detaching frame in SQLTransactionCoordinator::shutdown(). This might not be directly related bug but it is only bug I got when I was trying to search for "deleteAllDatabases".
Ahmad Saleem
Comment 7 2023-11-11 07:17:58 PST
(In reply to Ahmad Saleem from comment #6) > Something similar was fixed in Blink: > > https://chromium.googlesource.com/chromium/blink/+/ > 8462425975e2d8bc28b02d9c2416ddc9c8520aab > > It was about hang happening while detaching frame in > SQLTransactionCoordinator::shutdown(). > > This might not be directly related bug but it is only bug I got when I was > trying to search for "deleteAllDatabases". https://searchfox.org/wubkat/rev/3e2262b3476ecfb5666a35bcdd746d474c061b0d/Source/WebCore/Modules/webdatabase/SQLTransactionCoordinator.cpp#132
Note You need to log in before you can comment on or make changes to this bug.