0

I am getting this exception when my application closes:

enter image description here

This is the stack trace at that moment:

enter image description here

This is the thread list at that moment:

enter image description here

I am finding it difficult to determine exactly what is happening here. The stack suggests that the database engine (Pervasive) is attempting to communicate, but the thread being "GC Finalizer Thread" seems odd.

I'm not sure exactly what has been disposed that something is then trying to use. A network socket? The database connection? How can I tell?

I'm hoping someone else has been here before, or sees something in those images that I am not picking up on.

DonBoitnott
  • 10,787
  • 6
  • 49
  • 68
  • 1
    So seems database connection was disposed (so closed), and after that you try to write something to database over it. – Evk Oct 06 '16 at 12:00
  • @Evk No writing is being done, at least not by my code. This is after the application code has exited. – DonBoitnott Oct 06 '16 at 12:05
  • After app code and in finalizer sounds like maybe a commit is queued in the database context and is trying to apply on disposal? Connection at this point has already been cleaned up... – Charleh Oct 06 '16 at 12:10
  • Can you share your code? I suspect there is a misbehaving `using` somewhere. – raidensan Oct 06 '16 at 13:41
  • @raidensan This stuff is spread over hundreds of pages and thousands of lines. That's why I went with screens of the exceptions, instead. – DonBoitnott Oct 06 '16 at 14:04

1 Answers1

1

Should be a comment, but does not fit. So you said application code has exited at this moment. Most likely that means application you are running is now terminating. Now all pending finalizers are run to cleanup resources (for objects whos types declare those finalizers of course). In one of those finalizers (that is why you see GC.FinalizerThread here), something tries to write data to database (SqlClient in track trace suggests that is database, and NetworkStrem.Write suggests it is, well, write), but the connection has already been closed, so you see this exception.

Evk
  • 98,527
  • 8
  • 141
  • 191
  • That's where I'm at. Since it's Pervasive's finalizer, I obviously have no control over that. Also, it can't be a simple bug, or I'd be getting it everywhere, all the time. Connections are created and destroyed constantly. It's only when closing the app that this happens. Moreover, it seems linked to only certain forms that have to be opened first, so it's terribly complicated. That's why I'm trying to understand how a finalizer could be triggering a DB write in the first place, so I can determine what to do next. – DonBoitnott Oct 06 '16 at 12:32
  • 2
    Well you can write any code in finalizer, including db write. So most likely that pervasive does db write on Dispose of some of their class (like said above in comment - it might be commiting pending work on dispose). You don't call that Dispose explicitly somewhere - and so it is getting called by finalizer. So you might check first if you are not forgetting to Dispose some of their objects. – Evk Oct 06 '16 at 12:35