[odb-users] Mutex may not be released Re: It was blocked by
odb::sqlite::connection_pool_factory::create()
Sunny Sun
sunny.sun at ringcentral.com
Thu Jun 27 22:53:50 EDT 2024
If the Win32 SetEvent() function fails, it means there is something
fundamentally broken with synchronization primitives in the process
and whether you unlock a mutex or not doesn't really matter.
Yes, we really got win32_exception() when call odb::sqlite::connection().
Here is the steps:
1. Create odb.
auto db = std::shared_ptr<odb::sqlite::database>(new odb::sqlite::database(dbFile,
SQLITE_OPEN_READWRITE
| SQLITE_OPEN_CREATE
| SQLITE_OPEN_SHAREDCACHE
| SQLITE_OPEN_FULLMUTEX,
false,
"",
poolInTransP));
2. Init schema
3. Do task in transaction
{
odb::session commitDataSession;
auto connection = db->connection();
odb::transaction t (connection->begin ());
task();
t.commit ();
}
The above code throw win32_exception(), but not sure which line throw it.
We got 2 times win32_exception().
4. It was blocked by odb::sqlite::connection_pool_factory::create().
It really was blocked by odb::sqlite::connection_pool_factory::create().
odb::sqlite::connection_pool_factory::create() may be called by auto connection = db->connection(); 2which will call connection_pool_factory::connect().
At first we also suspected that the db file was damaged or occupied, and we tested it.
It may lead to other problems, but not the same with this issue.
This issue only happened once, and we did not find out the root cause.
We only find this issue same began with the win32_exception().
Any help will be appreciated. Thank you very much.
On Jun 25, 2024, at 18:39, Boris Kolpackov <boris at codesynthesis.com> wrote:
[EXTERNAL]
Sunny Sun <sunny.sun at ringcentral.com> writes:
We encountered a problem that was the thread was blocked by
odb::sqlite::connection_pool_factory::create().
We created a new db file with odb::sqlite::database, then we call
db->schema_version() which will call
odb::sqlite::connection_pool_factory::create().
Are you sure it is connection_pool_factory::create() that is blocking
and not connection_pool_factory::connect()?
connection_pool_factory::create() essentially calls sqlite3_open_v2()
and then executes a couple of PRAGMA statements, which I don't see how
they can block, at least not at the ODB level. Perhaps the file is locked
on the filesystem level or some such?
I noticed the following code snippet:
signal ()
{
if (waiters_ > signals_)
{
if (signals_++ == 0)
{
if (SetEvent (event_) == 0)
throw win32_exception ();
}
}
mutex_.unlock ();
}
If it throw win32_exception(), it will not unlock mutex.
If the Win32 SetEvent() function fails, it means there is something
fundamentally broken with synchronization primitives in the process
and whether you unlock a mutex or not doesn't really matter.
Are you observing this exception being thrown in your case?
Also, I don't see how it is connected to the create() function
above. Can you explain how this code is relevant to the problem
at hand?
More information about the odb-users
mailing list