CoreyKaylor / Lightning.NET

.NET library for LMDB key-value store
Other
401 stars 82 forks source link

Unhandled exception in lmdb64.dll #25

Closed PawelBaranowski closed 10 years ago

PawelBaranowski commented 10 years ago

This might not be a real issue, but I had no other means of contacting you. Sorry for that.

I recently came across Lightning.NET and decided to give it a try as a low-latency history provider for ASP.NET project I'm working on. It must be shared between several separate applications so I thought Lightning.NET might do the trick While using Lightning.NET I'm getting an unhandled exception in included lmdb64.dll that says:

Unhandled exception at 0x000000006C8C2371 (lmdb64.dll) in w3wp.exe: 0xC0000005: Access violation writing location 0x0000000000000008.

This is a code I'm using: http://pastebin.com/vR53qFGM

When I run unit tests they pass unless I debug-test and wait for a while. Then the same exception occurs.

Am I missing anything? Perhaps I'm breaking some workflow rules of lmbd? Is the environment or database open for too long or too short? Is it a good idea at all to employ Singleton pattern here? I'd be glad to receive any help.

ilyalukyanov commented 10 years ago

It's ok. Feel free to contact me any way which is convenient for you. I'll answer quickly as I'm on my cellphone now but, I think, it will work for you then. By calling the very first Transaction's Commit you have dispossed it. You've opened the database inside this transaction and its resourses were deallocated too on the Commit. When you call Get methods, you do it against the database which is not openned in the environment. All you need to do is to keep the transaction alive so don't commit it and make it accesable by the class members. You can open new transactions as children of this transaction and will be free to commit them. I should definitely workaround this case with some understandable exception. 14 ÆÅ×Ò. 2014 Ç. 13:37 ÐÏÌØÚÏ×ÁÔÅÌØ "baran25" notifications@github.com ÎÁÐÉÓÁÌ:

This might not be a real issue, but I had no other means of contacting you. Sorry for that.

I recently came across Lightning.NET and decided to give it a try as a low-latency history provider for ASP.NET project I'm working on. It must be shared between several separate applications so I thought Lightning.NET might do the trick While using Lightning.NET I'm getting an unhandled exception in included lmdb64.dll that says:

Unhandled exception at 0x000000006C8C2371 (lmdb64.dll) in w3wp.exe: 0xC0000005: Access violation writing location 0x0000000000000008.

This is a code I'm using: http://pastebin.com/vR53qFGM

When I run unit tests they pass unless I debug-test and wait for a while. Then the same exception occurs.

Am I missing anything? Perhaps I'm breaking some workflow rules of lmbd? Is the environment or database open for too long or too short? Is it a good idea at all to employ Singleton pattern here? I'd be glad to receive any help.

Reply to this email directly or view it on GitHubhttps://github.com/ilyalukyanov/Lightning.NET/issues/25 .

ilyalukyanov commented 10 years ago

I'm not sure about singleton here. I will answer you later. For now I could only say that it doesn't seem threadsafe 14 ÆÅ×Ò. 2014 Ç. 13:37 ÐÏÌØÚÏ×ÁÔÅÌØ "baran25" notifications@github.com ÎÁÐÉÓÁÌ:

This might not be a real issue, but I had no other means of contacting you. Sorry for that.

I recently came across Lightning.NET and decided to give it a try as a low-latency history provider for ASP.NET project I'm working on. It must be shared between several separate applications so I thought Lightning.NET might do the trick While using Lightning.NET I'm getting an unhandled exception in included lmdb64.dll that says:

Unhandled exception at 0x000000006C8C2371 (lmdb64.dll) in w3wp.exe: 0xC0000005: Access violation writing location 0x0000000000000008.

This is a code I'm using: http://pastebin.com/vR53qFGM

When I run unit tests they pass unless I debug-test and wait for a while. Then the same exception occurs.

Am I missing anything? Perhaps I'm breaking some workflow rules of lmbd? Is the environment or database open for too long or too short? Is it a good idea at all to employ Singleton pattern here? I'd be glad to receive any help.

Reply to this email directly or view it on GitHubhttps://github.com/ilyalukyanov/Lightning.NET/issues/25 .

PawelBaranowski commented 10 years ago

Thank you for answering so soon. Unfortunately, after changing the code to use a single transaction and removing all the Commit calls the problem persists. Also I still think I need to commit because the db will be shared across several processes. Are there any projects using your library I could have a look at? This could lead me to proper ways to use it.

ilyalukyanov commented 10 years ago

Sorry for the delay... I was overloaded by work. In the next couple of days I'll debug your code example carefully and provide working solution.

You haven't had to remove all the Commit calls but only the first one, in which transaction DB is opened. You should to Commit (or Abort) every child Transaction but not the root Transaction. Please have a look at changes I've made - http://pastebin.com/tgZ1xk33 You have two options (I've changed the code and marked them with comments):

ilyalukyanov commented 10 years ago

Hello,

I've checked your code precisely. First of all, I must say that I was wrong with my suggestion about commits. It's ok to commit the first transaction and then reuse db handle. It's said in LMDB documentation - http://symas.com/mdb/doc/group__mdb.html#gac08cad5b096925642ca359a6d6f0562a

I beleive, to solve your issue you should set LightningEnvironment.MapSize (MaxSize) to an appropriate value. When the database is full of data such an error could occur. Try to set larger value. I've reproduced your error and in my case setting this property to a larger value has helped.

Also, I've made your code a little safier. You can find my solution shared here: https://www.dropbox.com/s/15280f6uxkiucqs/ConsoleApplication4.zip

PawelBaranowski commented 10 years ago

Wow!

Thank you for such a complete answer. The solution you shared helped me and gave me some hints for my future work. I especially like the idea of using Lazy<> for singleton pattern.

Thanks a lot again for sharing your experience and time with me.

The issue is solved.

ilyalukyanov commented 10 years ago

You are welcome! I'm glad to help and feel free to contact me if you will face any further questions.