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

Null reference exception on fbcommand dispose [DNET316] #327

Closed
firebird-automations opened this issue May 14, 2010 · 20 comments
Closed

Null reference exception on fbcommand dispose [DNET316] #327

firebird-automations opened this issue May 14, 2010 · 20 comments

Comments

@firebird-automations
Copy link

Submitted by: Gerdus van Zyl (angelblaze)

Is duplicated by DNET368
Is duplicated by DNET386

Attachments:
FirebirdNullExceptionReproduce.zip

Votes: 6

I have been getting the following exception if I close an connection (or forget to close connection manually) before explicitly calling .Dispose() on all FbCommands created (I now put fbcommand object in a list and dispose of manually before connection close). Which is strange since I can't see where I keep die commands alive beyond the life of the connection. The part of my program which gives the problem is a database schema upgrade that runs in a background thread.

Object reference not set to an instance of an object.

stack trace:
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.RemovePreparedCommand(FbCommand command)
at FirebirdSql.Data.FirebirdClient.FbCommand.Release()
at FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize()

target site:
{Void RemovePreparedCommand(FirebirdSql.Data.FirebirdClient.FbCommand)}

Commits: f71e5d8

@firebird-automations
Copy link
Author

Commented by: Gerdus van Zyl (angelblaze)

Forgot to mention the exception isn't catchable, as in visual studio does not jump to the line in my program that gave the exception.

@firebird-automations
Copy link
Author

Commented by: Marc Bettex (mbettex)

I observed the same behavior. I don't know really what caused it in my case. It seems to happen kind of randomly, but it only when I have several threads that use the connector to query the database at the same time.

It seems that the FbConnectionInternal.preparedCommands field is cleared during the execution of the FbConnectionInternalRemovePerparedCommand, which causes an exception because the variable i is greater than zero but the size of the collection is zero.

I would have thought that this field was modified by another thread, but I'm not sure. I don't understand how another thread could modify this field, since it is the garbage collector that calls this method when the exception occurs, and it shouldn't be possible to use an object while it is being garbage collected. But I don't really see how the code in the loop could clear this field either. So yeah, I don't really have a clue of why this happens. It looks like very strange to me.

If you want to catch the exception in visual studio, type CTR + ALT + E in visual studio and check everything in the dialog. Then if the exception is thrown, the debugger will stop at this point.

EDIT:

Actually, after spending some more time, I found a place where I forgot to call dispose() on an FbCommand in my code. After adding that call and running tests that used to fail sometimes before, they don't fail anymore. It used to happen kind of randomly, so I cannot be sure that the problem is really solved, but it seems to work now. So yeah, Gerdus van Zyl is probably right when saying that the problem is caused by not calling dispose() an an FbCommand before the connection is closed.

@firebird-automations
Copy link
Author

Commented by: Eugeniy (hev)

Same problem. But during work with Entity Framework.
It was attempt to transfer project from MS SQL to Firebird. In MS SQL all was fine. So it is not about manual calling of Dispose() on any Commands.
In the same time only one thread access Entity Context so it is not about multi-threading.

Problems with reproduction.

Such kind of problems prevent from using of Firebird in any real .NET projects based on Entity Framework. Handling errors in some specific command/query may have work-around. But such kind of errors like this one don't have realistic work-around.

I think that priority should be changed to Blocker or Critical.

@firebird-automations
Copy link
Author

Commented by: Martin Turek (jskeletti)

I get sometimes a strange error while I use a program which was created with provider 2.5.1. Now I changed the version to 2.6 and get following error spontaneously, I can't say when and why it happens. Maybe you will know. It seems not to be cause by my application, in addition to that this error does not occur when I use the old provider version.

Error (sorry, but in german):

[4208] LPCS->Unhandled EXCEPTION -> OnCurrentDomain_UnhandledException
[4208] LPCS->EXCEPTION: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
[4208] bei FirebirdSql.Data.FirebirdClient.FbConnectionInternal.RemovePreparedCommand(FbCommand command)
[4208] bei FirebirdSql.Data.FirebirdClient.FbCommand.Release()
[4208] bei FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
[4208] bei System.ComponentModel.Component.Finalize()
[4208] LPCS->System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
[4208] bei FirebirdSql.Data.FirebirdClient.FbConnectionInternal.RemovePreparedCommand(FbCommand command)
[4208] bei FirebirdSql.Data.FirebirdClient.FbCommand.Release()
[4208] bei FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
[4208] bei System.ComponentModel.Component.Finalize()

@firebird-automations
Copy link
Author

Commented by: Gerdus van Zyl (angelblaze)

recently upgraded to 2.6.5 in conjunction with .net version 4 and problem still exists. The problem is intermittent as all good heisenbugs should be.

@firebird-automations
Copy link
Author

Commented by: Gerdus van Zyl (angelblaze)

updated to inform that bug still exist in newest version and in .net4/vs2010

@firebird-automations
Copy link
Author

Modified by: Gerdus van Zyl (angelblaze)

Version: 2.6 [ 10371 ]

environment: Windows 7, .net 3.5 sp1, visual studio 2008 => Windows 7, .net 3.5 sp1, visual studio 2008
Windows 7, .net 4, visual studio 2010

@firebird-automations
Copy link
Author

Commented by: Mert Ali Özalp (mert19)

I am using http://asp.net 4.0 and firebird 2.5 in my web site project. And i use firebird .net provider (for sure)

My web site is being used by only 5 - 10 users by now. I tried .net provider 2.5.2 and 2.6.5 but for both of them, I am getting the following exception for most of the time ....

Exception: System.NullReferenceException

Message: Object reference not set to an instance of an object.

StackTrace: at FirebirdSql.Data.FirebirdClient.FbCommand.RollbackImplicitTransaction()
at FirebirdSql.Data.FirebirdClient.FbCommand.Release()
at FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize()

Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
at FirebirdSql.Data.FirebirdClient.FbCommand.RollbackImplicitTransaction()
at FirebirdSql.Data.FirebirdClient.FbCommand.Release()
at FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean)
at System.ComponentModel.Component.Finalize()

But when only one user is using the site , no exception occurs, and when a second user enters the site, just at that time the exception occurs

and goes on occurring as long as more than one user is using the site.

I think there is problem in the user session management mechanism of the firebird .net provider ...

Could any one give me any advice or solution for this problem ?

@firebird-automations
Copy link
Author

Commented by: Can A. Course (canacourse)

Happening to me as well but I am calling dispose() or using usings in the right places. Very random and hard to track down.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

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

resolution: Fixed [ 1 ]

Fix Version: 2.7 [ 10431 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is duplicated by DNET368 [ DNET368 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is duplicated by DNET386 [ DNET386 ]

@firebird-automations
Copy link
Author

Commented by: Leonard Wennekers (l.wennekers)

We are using FB 2.5.1 with the provider 2.7. 7 in a Windows 7, .net 4, visual studio 2010
environment and we still got those exceptions. It's hard to track down why the exception
occurs. It's once in a while but very unpleasant... I hope that other can point me out what
they did to solve this problem

@firebird-automations
Copy link
Author

Commented by: Andrey (andrew_1985)

It still appears in NETProvider-3.0.2.0-NET40.7z with FB 2.5!! It is so frustrating

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Provide a test case.

@firebird-automations
Copy link
Author

Commented by: Yiannis Bourkelis (yiannis)

I am also experiencing the same issue. The error message I get is:

#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠
Object reference not set to an instance of an object.

Stack Trace:
at FirebirdSql.Data.FirebirdClient.FbCommand.Release()
at FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize()
#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠

This error pops up randomly, once every one or two days and causes my app to crash.

I am using firebird net provider 2.7.7, targeting net framework 2.0.
I see this error on a Windows Server 2008 R2 machine.
The database is accessed from multiple threads.

Any ideas how to fix this?

@firebird-automations
Copy link
Author

Commented by: Bill Volz (billvolz)

Making sure that all your command & connection objects are wrapped in using tags will prevent this from occurring.

i.e.

using(var conn = new FbConnection())
{
using(var cmd = new FbCommand(conn,...))
{
cmd.Execute(..);
}
}

If you want to reproduce this error create an IIS http://Asp.net web application that uses the provider but don't call dispose on the objects. It may take a few attempts for it to occur but it will eventually occur.

@firebird-automations
Copy link
Author

Commented by: Yiannis Bourkelis (yiannis)

Thank you Bill, I will try your suggestion.

If you have a working solution to reproduce this issue please post it here so that Jiri will be able to fix it.

I will also try to create a winforms reproducable test case and post it here

@firebird-automations
Copy link
Author

Commented by: Yiannis Bourkelis (yiannis)

Finally I was able to create a reproducable case for this exception.

Steps to reproduce:

Inside the zip file you will find the folder FirebirdNullExceptionReproduce.
Open FirebirdNullExceptionReproduce.sln inside.

Run the app and wait for some seconds.
You sould be able to see one of the following exceptions:

System.NullReferenceException
Object reference not set to an instance of an object

or

System.AccessViolationException
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

@firebird-automations
Copy link
Author

Modified by: Yiannis Bourkelis (yiannis)

Attachment: FirebirdNullExceptionReproduce.zip [ 12410 ]

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