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 crashes after unsuccessful remapping of the lock table's shared memory [CORE4500] #4819

Closed
firebird-automations opened this issue Jul 25, 2014 · 9 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Y. Numai (y-numai)

My C#⁠ Windows Service Application uses .NET Data Provider and FB Embeded server (fbembed.dll).
However, it sometimes crashes when it connects to a firebird database file.

===EventLog(Application) EID 1026===
Exception: System.AccessViolationException
Stack:
at FB_1236665269_Class.isc_attach_database(IntPtr[], Int16, Byte[], Int32 ByRef, Int16, Byte[])
at FB_1236665269_Class.isc_attach_database(IntPtr[], Int16, Byte[], Int32 ByRef, Int16, Byte[])
at FirebirdSql.Data.Client.Native.FesDatabase.Attach(FirebirdSql.Data.Common.DatabaseParameterBuffer, System.String, Int32, System.String)
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnectionPool.Create()
at FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckOut()
at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
...

===EventLog(Application) EID 1000===
Faulting application name: MyApp.exe, version: 1.0.1.0, time stamp: 0x52eb5d90
Faulting module name: fbembed.DLL, version: 2.5.1.26351, time stamp: 0x4e89609d
Exception code: 0xc0000005
Fault offset: 0x000000000027963b
Faulting process id: 0x450
Faulting application start time: 0x01cf7f979c1b46a3
Faulting application path: C:\Program Files\MyApp\MyApp.exe
Faulting module path: C:\Program Files\MyApp\fbembed.DLL
...

When my app crashed, it created firebird.log as below.

====firebird.log=====
ServerName Fri Jun 20 23:51:31 2014
Fatal lock manager error: ISC_map_file failed (reattach shared file), errno: 1224

I investigated my application crash dump file, and I finally found out that my app has crashed at fwrite()
in the method "LockManager::bug()."

====ll.1651-1655 at Firebird-2.5.1.26351-0\src\lock\lock.cpp, ====
if (fd)
{
fwrite(m_header, 1, m_header->lhb_used, fd);
fclose(fd);
}

I have a hunch that if "LockManager::acquire_shmem()" failed to "attach_shared_file" (l.1149 at lock.cpp), it calls "LockManager::bug()" (l.1150 at lock.cpp).
"LockManager::bug()" referes "m_header->lhb_used" as it shows above.

However, if "LockManager::attach_shared_file()" fails, m_header will be NULL.

====ll.337-340 at Firebird-2.5.1.26351-0\src\lock\lock.cpp, ====
m_header = (lhb*) ISC_map_file(status, name.c_str(), initialize, this, m_memorySize, &m_shmem);

if \(\!m\_header\)
	return false;

==================================================================

Therefore, NULL-reference seems to occur at "fwrite(m_header, 1, m_header->lhb_used, fd)."

Commits: cb90a3a 31bdbe0 FirebirdSQL/fbt-repository@03e6250 FirebirdSQL/fbt-repository@fe8a70e

@firebird-automations
Copy link
Collaborator Author

Modified by: Y. Numai (y-numai)

summary: Firebird embeded server crashes => Firebird embeded server crashes because of AccessViolationException

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

What path is the database file in?

Have you confirmed that the local user has read/write access to this folder?

@firebird-automations
Copy link
Collaborator Author

Commented by: Y. Numai (y-numai)

The answer for your first question is....
The database file which my application failed to access is "C:\MyAppData\data\2014-06-20.db."

About the second question,
my application works as local system account (NT_Authority\SYSTEM) and
the local system account has NTFS access rights to read/write to the above database file.
Therefore, I certainly have a right permission to access the database and there is no problem related to this.

I think you might misunderstand what I am talking about.
The point I want to describe is that *NULL pointer reference* after "fatal lock manager error"
but not "fatal lock manager error " itself.

My application insert data to the database for every minite.
In addition to this, the data backup application works in the same computer as my application does work.
This is the reason why "Fatal lock manager error: ISC_map_file failed (reattach shared file)" occurred
to the database file (because of the simultaneous access).
So far, Firebird works correctly.

However, after this error-catch, "LockManager::bug()" is called at l.1150 at lock.cpp (Firebird-2.5.1.26351-0),
then an application that uses fbembed.dll always crashes because of NULL pointer reference.
This is what I am pointing out.

Could you see the actual code and review this issue?
I would appriciate if you get a resolution for this problem.

Thank you.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

assignee: Dmitry Yemanov [ dimitr ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

summary: Firebird embeded server crashes because of AccessViolationException => Firebird crashes after unsuccessful remapping of the lock table's shared memory

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

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

resolution: Fixed [ 1 ]

Fix Version: 3.0 Beta 1 [ 10332 ]

Fix Version: 2.5.4 [ 10585 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

It should be fixed now, thanks.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

QA Status: Cannot be tested

@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