sqlitedict icon indicating copy to clipboard operation
sqlitedict copied to clipboard

Deadlock on exception when opening connection

Open arnauorriols opened this issue 7 years ago • 4 comments

When SqliteDict is initialized, a connection to SQLite is opened (in here). This connection might fail.

If an exception happens, the connection does not get opened. However, the initialization still tries to create the table. In the commit of that operation, the execution is deadlocked, because the code keeps waiting infinitely in the req Queue.

arnauorriols avatar Dec 18 '18 15:12 arnauorriols

Hi @arnauorriols, can you add a code example that reproduces this error (so we can fix it)?

menshikh-iv avatar Jan 17 '19 03:01 menshikh-iv

I think I'm having the same issue. Steps to reproduce:

  • create write protected folder.
  • try to open a non-existing DB in the folder sqlitedict.SqliteDict("/tmp/write_protected/non_existing.sqlite", tablename="test", autocommit=True).

This crashes internally (traceback visible on stdout) but never returns, looking like the mentioned deadlocked.

bluenote10 avatar Apr 29 '19 13:04 bluenote10

Hi @arnauorriols, can you add a code example that reproduces this error (so we can fix it)?

I've opened #97 proposing a fix.

arnauorriols avatar Jun 21 '19 00:06 arnauorriols

@arnauorriols realized that #97 has a race condition. #107 is my fresh approach that solves the undetected failure to open the connection (on first command exection) which currently leads to a deadlock in the calling code. It also avoids the race condition when the thread's run() is slower to set self.exception than the calling code executes a command (including a then false negative exception check) and then deadlocking on the answer.

padelt avatar Feb 21 '20 16:02 padelt