I am very confused. I never explicitly "open" a database. I use sessions that issue a series of queries & commands, such as 'XQUERY', 'CREATE DB', and the like. I don't issue any 'OPEN' or 'CLOSE' commands.
As you already guessed, the XQUERY commands is also capable of opening databases (otherwise, there would be no chance to access data inside those instances).
Suppose one client run an XQUERY against a db, which involves (internally) one or more 'OPEN' calls, then accesses, then 'CLOSE' commands --- how do you synchronize this client with others? Do you have a master lock so that the server processes only one query/command at a time?
The pin counter is used to find out how often a particular database is opened. Our architecture supports multiple read and single write operations at the same time [1].
if not, your assumption that you can throw an error in CreateDB.run if the db is pinned is wrong. Instead, you'll need a 'wait_until_unpinned' method [...]
Well, it's tedious to guess what might be the problem as long as we can't reproduce your particular use case. If you believe you have some concrete ideas what might be the problem, though, feel free to check out the sources and give it a try.
Christian