Bug 32626 - Move some code from Database::~Database() to Database::close()
Summary: Move some code from Database::~Database() to Database::close()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Dumitru Daniliuc
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-16 12:05 PST by Dumitru Daniliuc
Modified: 2009-12-18 17:52 PST (History)
5 users (show)

See Also:


Attachments
patch (3.16 KB, patch)
2009-12-16 12:26 PST, Dumitru Daniliuc
dumi: commit-queue-
Details | Formatted Diff | Diff
patch (3.44 KB, patch)
2009-12-16 18:41 PST, Dumitru Daniliuc
dimich: review+
dumi: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dumitru Daniliuc 2009-12-16 12:05:22 PST
Currently, DatabaseTracker is notified that a Database is closing/closed in the Database's destructor. At that point, we are very limited in what we can do, because the Database object is being destroyed. Instead, it seems like the correct thing to do is notify the DatabaseTracker that a database is being closed in the close() method.
Comment 1 Dumitru Daniliuc 2009-12-16 12:26:07 PST
Created attachment 45004 [details]
patch
Comment 2 WebKit Review Bot 2009-12-16 12:27:45 PST
style-queue ran check-webkit-style on attachment 45004 [details] without any errors.
Comment 3 Michael Nordman 2009-12-16 17:58:51 PST
355     if (m_document->databaseThread())
356         m_document->databaseThread()->unscheduleDatabaseTasks(this);

Given the ASSERT on line 335, looks like we don't need to test for null'ness here.


359     m_document->removeOpenDatabase(this);

This looks like a threading bug waiting to happen? The doc->addOpenDatabase() method is being called on the main thread, but the call to doc->removeOpenDatabase() happens on the db thread (per the ASSERT on line 336). But the underlying collection being used by the Document is not thread safe.

This call to remove() used to be in the dtor, which contains code that indicates it can happen on a background thread in theory. In practice, who knows how often that does happen.

This change as coded will guarantee that the underlying set is accessed in a non-thread-safe fashion. I think you need to poke at this in some way.
Comment 4 Dumitru Daniliuc 2009-12-16 18:41:27 PST
Created attachment 45031 [details]
patch

(In reply to comment #3)
> 355     if (m_document->databaseThread())
> 356         m_document->databaseThread()->unscheduleDatabaseTasks(this);
> 
> Given the ASSERT on line 335, looks like we don't need to test for null'ness
> here.

good point. removed.

> 359     m_document->removeOpenDatabase(this);
> 
> This looks like a threading bug waiting to happen? The doc->addOpenDatabase()
> method is being called on the main thread, but the call to
> doc->removeOpenDatabase() happens on the db thread (per the ASSERT on line
> 336). But the underlying collection being used by the Document is not thread
> safe.
> 
> This call to remove() used to be in the dtor, which contains code that
> indicates it can happen on a background thread in theory. In practice, who
> knows how often that does happen.
> 
> This change as coded will guarantee that the underlying set is accessed in a
> non-thread-safe fashion. I think you need to poke at this in some way.

you're right. i think this should be fixed now, please take another look.
Comment 5 WebKit Review Bot 2009-12-16 18:42:11 PST
style-queue ran check-webkit-style on attachment 45031 [details] without any errors.
Comment 6 Michael Nordman 2009-12-16 19:09:08 PST
> you're right. i think this should be fixed now, please take another look.

 365     DatabaseTracker::tracker().removeOpenDatabase(this);
 366     ref();
 367     callOnMainThread(documentRemoveOpenDatabase, this);


that works for me
Comment 7 Dumitru Daniliuc 2009-12-18 11:35:56 PST
Can a reviewer please take a look at this patch?
Comment 8 Dmitry Titov 2009-12-18 12:28:02 PST
r=me

On landing, could you please add a small comment against the ref() to say where is a balancing deref()?

366     ref();
367     callOnMainThread(documentRemoveOpenDatabase, this);
Comment 9 Dumitru Daniliuc 2009-12-18 12:29:25 PST
(In reply to comment #8)
> r=me
> 
> On landing, could you please add a small comment against the ref() to say where
> is a balancing deref()?
> 
> 366     ref();
> 367     callOnMainThread(documentRemoveOpenDatabase, this);

Will do. Thanks for taking a look at this patch!
Comment 10 Dumitru Daniliuc 2009-12-18 17:52:56 PST
Landed as r52367.