Ads by The Lounge
My name is Oren Eini and you can reach me by email: Ayende@ayende.com Cell: +972 52-548-6969 / +1 201-820-0222 About me
Suggest new posts
NHibernate Homepage
Challenge: Find the bug
This piece of code caused a crashing bug on a QA server ( and we are lucky it didn’t go to production ).
Can you spot the bug?
I will give you a hint, it is the code that isn’t there.
Print | posted on Tuesday, May 26, 2009 11:42 PM
Is a transaction or some other synchronization method missing here? That is, it seeks the values, then deletes them. The data could change during the deletions.
It's in the loop... ?
I think, you're missing a check before deleting it ...
Where does 'data' comes from? (The ApplyToKeyAndActiveVersions line).
Ayende, where's your sweet spot in the Esent database? Do you miss good ol' days of WINAPI programming, or is Esent exceptionally performant/stable/powerful/whatever? Maybe there was a reason Microsoft has hidden it?
No, that is handled elsewhere
Dave,Another table that we join against.
Gloubidou,You are close...Vadi,No, that is not it.Rafal,I use it when I need a local DB. It is really easy to use when you get how it is working.It helps that it is the only local DB with true threading support.
maybe issue is related with closure of the session and data variables here: v=>Api.JetDelete(session, data)
Alexander,No, that is not it
Maybe "v => Api.JetDelete(session, data)" can't be run thru delegate for some reason?
meo,No, that is not it. It works just fine.
I take it the crash is a stack overflow from an infinite loop and that you are either missing a breaking condition or not doing something that would should effect the 'position'..Basically no idea, is this something that will probably only make sense when illustrated and explained?
What happens to the table cursor after Api.JetDelete()?And does Api.JetDelete() immediately remove the table row or only mark it as deleted? Otherwise scenario could be:- Api.JetDelete moves cursor forward- Api.TryMovePrevious moves cursor backwards (to same row)=> infinite loop
Stephen, That would hang, not crash...
Ah, true ;)(btw ayende, having problems submitting comments from ie7/8- not sure if its just me, hitting submit doesn't do anything it just sits there).
Stephen,No stack overflow, no, and not an infinite loop, but you should concentrate on the loop
Gerke,It is marking that for deletion in the end of the current transaction, TryMovePrevious is not the issue.The loop will terminate at the expected time.
I guess that you are trying to clean expired values (stuff we don't care about anymore).. thus having a big result set would pose a problem... am I right?
do we need to know the contract of the jet api to find the problem?
If the Api.RetrieveColumnAsString gets the first one then the Api.TryMovePrevious would never go to the rest but stop when the first one is deleted.
gloubidou,Tada, you are _very_ close. aaron,No, you don't.
DuvallBuck,No, that is not the behavior we have
How often do values expire?
You're calling the function on a fixed timer and it's being executed again, before the previous execution has finished. Considering it results in a crash, it's probably stacking a good number of times.
That is a user defined value. In the system that we are talking abut, 24 hours
Michael,Huh?What timer? There isn't any external code involved that affect the bug in this function
The call to Api.JetDelete should probably be called with session and key, not session and keyS (deleting everything)?
Sander,keys is the variable holding the table name, not a collection. It is instruction to delete the current row.
Two Api.JetDelete calls?
Everyone, Notice what I said, what is the code that IS NOT THERE?!
You get the version but do not check it has expired? TBH I am guessing based on what I would expect to see rather than understanding the code / api that this is using but it seems like the most logical thing.
Neal, No, that is not that.And you don't need to understand anything about the API to see the problem. The problem is that until you see the problem, you don't know what it is.I am actually encouraged that no one managed to find it.It means that I am not that stupid
Commit size will become huge in this case... Since you say that it is about code that isn't there, all I am able to come with is fixing a maximum of expired values to be processed in the loop and process the remaining later. That's similar to ORA-01555 snapshot too old!
gloubidou,TADA! You got it!When you hit it exactly right, you may get a LOT of expired values.Those expired values can be big enough to hit the commit limit, and cause an error!So I _was_ stupid, I thought so! :-)
Wow... gloubidou I am impress.Oren, how did you uncover the bug? If the application throw an exception somewhere then it's probably not that hard to trace down the culprit. Did you catch it through stress testing?
Silly question: why is there a commit limit?
As I said, we run into this error in QA.Once I had the stack trace, and the error, it was really obvious what was wrong
Powered by: Copyright © Ayende Rahien