office-gobmx/dbaccess
Lionel Elie Mamane 1981819e81 fdo#63391 deadlock on opening .odb file that auto-connects to the database
Let foo.odb be a database file that has a macro that connects to the
Database on "Open Document" event (and needs to prompt user for
user/password).

There was a race condition between two actions:

 1) the asynchronous treatment of "OnFirstControllerConnected" in dbaui::OApplicationController,
    which tries to get dbaui::OApplicationController's mutex

 2) the StarBasic macro calling dbaui::OApplicationController::connect
    which needs to display a dialog (to get username and password),
    and thus puts that dialog in the main thread's event queue
    and waits for it ... with dbaui::OApplicationController's mutex held

Now, if "1)" is before "2)" in the event queue of the the main thread,
*but* "1)" is executed *after* "2)" has taken the lock, there is a deadlock.

Fix:

 1) Make OnFirstControllerConnected synchronous.
    Make sure (by taking mutex in dbaui::OApplicationController::attachFrame, its ancestor in the call graph)
    that nothing else will happen with the OApplicationController as long as it is not finished.
    ---> it does not need to take mutex itself anymore

    This avoids the "order in the asynchronous events" dependency.

 2) Change dbaui::OApplicationController::ensureConnection to do the user prompting
    WITHOUT HOLDING the mutex, and use the mutex "only" to protect actually assigning
    the connection to m_xDataSourceConnection.

    Theoretically, in some race condition, we could connect twice and then discard one connection <shrug>.
    ensureConnection will never return the discarded connection, though.

    (I think I got that right with respect to http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html)

    This keeps it from locking on another condition while holding the mutex.

Change-Id: Iab1bbec5d5df12bb89d027d43e498c78c92ffc32
Reviewed-on: https://gerrit.libreoffice.org/3310
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
2013-04-29 12:58:23 +00:00
..
inc update pch 2013-04-25 12:11:53 +02:00
qa Java cleanup, remove unused imports 2013-04-26 08:29:38 +02:00
source fdo#63391 deadlock on opening .odb file that auto-connects to the database 2013-04-29 12:58:23 +00:00
uiconfig Access Query Properties Dialog from toolbar too 2013-04-23 23:52:51 +02:00
util
win32/source/odbcconfig
AllLangResTarget_dba.mk gbuild: drop empty use_packages calls 2013-04-24 05:18:15 +00:00
AllLangResTarget_dbmm.mk gbuild: drop empty use_packages calls 2013-04-24 05:18:15 +00:00
AllLangResTarget_dbu.mk gbuild: drop uses of removed packages 2013-04-24 05:18:03 +00:00
AllLangResTarget_sdbt.mk gbuild: drop empty use_packages calls 2013-04-24 05:18:15 +00:00
CppunitTest_dbaccess_macros_test.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
Executable_odbcconfig.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
JunitTest_dbaccess_complex.mk
JunitTest_dbaccess_unoapi.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
Library_dba.mk dbaccess: {DECLARE,IMPLEMENT}_CONSTASCII_USTRING are no longer needed 2013-04-25 11:02:34 +02:00
Library_dbaxml.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
Library_dbmm.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
Library_dbu.mk dbaccess: {DECLARE,IMPLEMENT}_CONSTASCII_USTRING are no longer needed 2013-04-25 11:02:34 +02:00
Library_sdbt.mk gbuild: drop uses of removed packages 2013-04-24 05:18:03 +00:00
Makefile
Module_dbaccess.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
Package_inc.mk Move to MPLv2 license headers, with ESC decision and author's permission. 2013-04-22 09:37:38 +01:00
README
UIConfig_dbaccess.mk
UIConfig_dbapp.mk
UIConfig_dbbrowser.mk
UIConfig_dbquery.mk
UIConfig_dbrelation.mk
UIConfig_dbtable.mk
UIConfig_dbtdata.mk

Database access tools, for "base" database application