Issue Details (XML | Word | Printable)

Key: CORE-900
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Alexander Peshkov
Reporter: Diane Downie
Votes: 0
Watchers: 1

If you were logged in you would be able to see more operations.
Firebird Core

Deadlock when attaching simultaneously with services and standard APIs

Created: 16/Aug/06 03:24 AM   Updated: 19/Jan/16 05:12 AM
Component/s: Engine
Affects Version/s: 1.5.3
Fix Version/s: 2.1 Alpha 1, 2.0.2

Firebird Superserver Windows
Windows 2003 SP1 (test virtual pc)
Issue Links:

QA Status: No test

 Description  « Hide
When 2 connections race to attach to a single database, one via the isc_service_attach and one via isc_attach_database a deadlock can occur. The following are the call stacks for the 2 threads in question. The mutex involved are those created by JRD_SS_MUTEX_LOCK and SecurityDatabase::lock().
Full fbserver.dmp is available for this issue.

ChildEBP RetAddr Args to Child
02cee494 7c822124 7c83970f 00000328 00000000 ntdll!KiFastSystemCallRet
02cee498 7c83970f 00000328 00000000 00000000 ntdll!NtWaitForSingleObject+0xc
02cee4d4 7c839620 00000000 00000004 02cee640 ntdll!RtlpWaitOnCriticalSection+0x19c
02cee4f4 004068ab 00582940 00421e4e 00582940 ntdll!RtlEnterCriticalSection+0xa8
02cee4fc 00421e4e 00582940 02cee790 004220ff fbserver!THD_mutex_lock+0xb [c:\40\buildparts\firebird\superserver\src\jrd\thd.cpp @ 729]
02cee508 004220ff 02ceeb5c 02cee790 02cee980 fbserver!SecurityDatabase::lock+0xe [c:\40\buildparts\firebird\superserver\src\jrd\pwd.cpp @ 130]
02cee5d8 004222b5 02cee790 02cee6a8 02cee6b4 fbserver!SecurityDatabase::lookup_user+0x6f [c:\40\buildparts\firebird\superserver\src\jrd\pwd.cpp @ 178]
02cee664 0045f22f 02cee790 02ceeb5c 00000000 fbserver!SecurityDatabase::verifyUser+0x65 [c:\40\buildparts\firebird\superserver\src\jrd\pwd.cpp @ 387]
02cee8fc 0041d29c 00000000 02ceeb7b 02ceeb5c fbserver!SCL_init+0x1bf [c:\40\buildparts\firebird\superserver\gen\jrd\scl.cpp @ 908]
02cef904 0040d970 02cefc34 00000006 02cefaf0 fbserver!jrd8_attach_database+0x8ac [c:\40\buildparts\firebird\superserver\src\jrd\jrd.cpp @ 1043]
02cefbf4 0051ee5c 02cefc34 00ff0006 00ff207c fbserver!isc_attach_database+0x280 [c:\40\buildparts\firebird\superserver\src\jrd\why.cpp @ 768]
02cefe84 00521fea 0259f01c 00000013 00ff4660 fbserver!attach_database+0x10c [c:\40\buildparts\firebird\superserver\src\remote\server.cpp @ 797]
02ceff4c 005226a8 0259f01c 00ff42d0 00ff4550 fbserver!process_packet+0x11a [c:\40\buildparts\firebird\superserver\src\remote\server.cpp @ 3090]
02ceff84 7c349565 0259f01c 00000000 00000000 fbserver!thread+0xd8 [c:\40\buildparts\firebird\superserver\src\remote\server.cpp @ 4863]
02ceffb8 77e6608b 025a33f8 00000000 00000000 MSVCR71!_endthreadex+0xa0
02ceffec 00000000 7c3494f6 025a33f8 00000000 kernel32!BaseThreadStart+0x34

ChildEBP RetAddr Args to Child
0368de94 7c822124 7c83970f 00000338 00000000 ntdll!KiFastSystemCallRet
0368de98 7c83970f 00000338 00000000 00000000 ntdll!NtWaitForSingleObject+0xc
0368ded4 7c839620 00000000 00000004 0368f194 ntdll!RtlpWaitOnCriticalSection+0x19c
0368def4 004068ab 0057f120 004069ec 0057f120 ntdll!RtlEnterCriticalSection+0xa8
0368defc 004069ec 0057f120 00000000 0041c5a2 fbserver!THD_mutex_lock+0xb [c:\40\buildparts\firebird\superserver\src\jrd\thd.cpp @ 729]
0368df08 0041c5a2 0057f120 00582958 00000000 fbserver!THD_rec_mutex_lock+0x1c [c:\40\buildparts\firebird\superserver\src\jrd\thd.cpp @ 1371]
0368e0b4 0041cb48 0368e128 00582958 0368ef14 fbserver!init+0xc2 [c:\40\buildparts\firebird\superserver\src\jrd\jrd.cpp @ 5563]
0368f0ac 0040d970 00582958 0000004a 0368f298 fbserver!jrd8_attach_database+0x158 [c:\40\buildparts\firebird\superserver\src\jrd\jrd.cpp @ 673]
0368f39c 00422002 00582958 00000000 0368f4d0 fbserver!isc_attach_database+0x280 [c:\40\buildparts\firebird\superserver\src\jrd\why.cpp @ 768]
0368f5d4 00422106 0052ec71 0368f79c 0368fa34 fbserver!SecurityDatabase::prepare+0x112 [c:\40\buildparts\firebird\superserver\src\jrd\pwd.cpp @ 303]
0368f6a4 004222b5 0368f79c 0368f784 0368f764 fbserver!SecurityDatabase::lookup_user+0x76 [c:\40\buildparts\firebird\superserver\src\jrd\pwd.cpp @ 178]
0368f730 00404c7c 0368f79c 0368f820 00000000 fbserver!SecurityDatabase::verifyUser+0x65 [c:\40\buildparts\firebird\superserver\src\jrd\pwd.cpp @ 387]
0368fa34 00417df8 0000000b 00ff4804 0000002b fbserver!SVC_attach+0x32c [c:\40\buildparts\firebird\superserver\src\jrd\svc.cpp @ 541]
0368fb2c 004102fb 0368fc3c 0000000b 00ff4804 fbserver!jrd8_service_attach+0x98 [c:\40\buildparts\firebird\superserver\src\jrd\jrd.cpp @ 3393]
0368fbf8 0051e80b 0368fc3c 005a000b 00ff4804 fbserver!isc_service_attach+0x16b [c:\40\buildparts\firebird\superserver\src\jrd\why.cpp @ 4339]
0368fe8c 00522004 02e33bc0 02e33830 00000000 fbserver!port::service_attach+0xfb [c:\40\buildparts\firebird\superserver\src\remote\server.cpp @ 4435]
0368ff4c 005226a8 00f6005c 02e33830 02e33ab0 fbserver!process_packet+0x134 [c:\40\buildparts\firebird\superserver\src\remote\server.cpp @ 3095]
0368ff84 7c349565 00f6005c 00000000 00000000 fbserver!thread+0xd8 [c:\40\buildparts\firebird\superserver\src\remote\server.cpp @ 4863]
0368ffb8 77e6608b 026cfee8 00000000 00000000 MSVCR71!_endthreadex+0xa0
0368ffec 00000000 7c3494f6 026cfee8 00000000 kernel32!BaseThreadStart+0x34

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Alexander Peshkov added a comment - 17/Aug/06 08:32 AM
I've just commited a very simple fix. Taking into account, that locked server is bad thing, I suggest to backport it to RELEASE branch, and this is the main reason why I've made fix simple. Please review it and decide, should it go to RELEASE or not.

After it I'll commit to HEAD a better fix, removing need to lock something in jrd8_service_attach(), but requiring more changes in SecurityDatabase.

Diane Downie added a comment - 18/Aug/06 01:27 PM
I would be like to test the 1.5.3 backport in my environment that reproduced the problem. I can build sources, so I would just need the files affected to start testing.

Alexander Peshkov added a comment - 28/Feb/07 04:19 AM
Fix is also backported to B2_0_Release, but currently I'm not sure which version should be marked in Fix Versions - 2.0.1 or (missing currently) 2.0.2.