Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebird hangs in embed mode [CORE4753] #5057

Closed
firebird-automations opened this issue Apr 16, 2015 · 7 comments
Closed

Firebird hangs in embed mode [CORE4753] #5057

firebird-automations opened this issue Apr 16, 2015 · 7 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Denis (artden)

Attachments:
FTBugTest.cpp

Firebird embed hangs in isc_attach_database if to execute new application during previous connection exists. Here is my example how to reproduce it (look at HANGS HERE comment):

#⁠include <Windows.h>
#⁠include <string>

#⁠include "ibase.h"

#⁠pragma comment(lib, "fbclient_ms.lib")

const std::string server_and_path = "d:\\DATABASE.FDB";
const std::string process = "C:\\Windows\\System32\\calc.exe";
const unsigned StatusLen = 20;

void connect1()
{
isc_db_handle db_handle = nullptr;
ISC_STATUS status_vect[StatusLen] = {};
char pdb[1] = { isc_dpb_version1 };

// connect 
isc\_attach\_database\(
	status\_vect,
	server\_and\_path\.size\(\),
	server\_and\_path\.c\_str\(\),
	&db\_handle,
	sizeof\(pdb\),
	pdb
\);

// start process

STARTUPINFOA si = \{\};
si\.cb = sizeof\(si\);
PROCESS\_INFORMATION pi = \{\};
int res = CreateProcessA\(
	process\.c\_str\(\),  // lpApplicationName
	NULL,             // lpCommandLine
	NULL,             // lpProcessAttributes
	NULL,             // lpThreadAttributes
	TRUE,             // bInheritHandles
	DETACHED\_PROCESS, // dwCreationFlags
	NULL,             // lpEnvironment
	NULL,             // lpCurrentDirectory
	&si,              // lpStartupInfo
	&pi               // lpProcessInformation
\);

// disconnect
isc\_detach\_database\(status\_vect, &db\_handle\);

}

void connect2()
{
isc_db_handle db_handle = nullptr;
char pdb[1] = { isc_dpb_version1 };

ISC\_STATUS status\_vect\[StatusLen\] = \{\};

// connect
isc\_attach\_database\( // <\- HANGS HERE
	status\_vect,
	server\_and\_path\.size\(\),
	server\_and\_path\.c\_str\(\),
	&db\_handle,
	sizeof\(pdb\),
	pdb
\);

isc\_detach\_database\(status\_vect, &db\_handle\);

}

int main(int argc, char* argv[])
{
connect1();
connect2();
return 0;
}

Commits: 67383e1 840ac35 FirebirdSQL/fbt-repository@b8313be FirebirdSQL/fbt-repository@798bba3

@firebird-automations
Copy link
Collaborator Author

Commented by: Denis (artden)

Example to reproduce

@firebird-automations
Copy link
Collaborator Author

Modified by: Denis (artden)

Attachment: FTBugTest.cpp [ 12705 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

assignee: Vlad Khorsun [ hvlad ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

The reason is that child process by default inherits all handles of parent process.
In our case child process keeps syncronization objects used by Firebird open after parent process detaches database.
At next attempt to attach database engine tries to initialize lock table and failed to "syncronize"
with child process (which have no idea about Firebird).

Obvious workaround is to run child process with bInheritHandles == FALSE, but this is not always possible and
could limit developers of embedded applications.

The proposed fix is to explicitly disable handle inheritance for named syncronization objects used by the engine.

Fix is committed into v2.5 tree, please verify it with next snapshot build.

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Simplified test case, using FB3 embedded connection:

firebird>isql c:\temp\A.FDB
Database: c:\temp\A.FDB
SQL> shell start calc;
SQL> connect c:\temp\a.fdb;
Commit current transaction (y/n)?y
Committing.

Hung with high CPU load at this point until calc.exe is terminated.

Database: c:\temp\a.fdb
SQL> exit;

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 3.0 Beta 2 [ 10586 ]

Fix Version: 2.5.5 [ 10670 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants