Open the database only once when callers arrive concurrently

_getConnectionAsync() checked for an existing connection and then awaited
several filesystem operations before assigning one, so callers arriving in
that window each opened their own. Only the last was kept, and the rest
stayed open and unreachable, holding a mozStorage thread apiece until
shutdown.
This commit is contained in:
Dan Stillman 2026-08-21 16:06:49 -04:00
parent 9e45191b22
commit e8055dfdf2

View file

@ -1548,6 +1548,18 @@ Zotero.DBConnection.prototype._getConnectionAsync = async function () {
throw new Error("Database permanently closed; not re-opening");
}
// Opening is asynchronous, so callers arriving while it's under way share the same attempt
if (!this._openPromise) {
this._openPromise = this._openConnectionAsync()
.finally(() => {
this._openPromise = null;
});
}
return this._openPromise;
};
Zotero.DBConnection.prototype._openConnectionAsync = async function () {
this._debug("Asynchronously opening database '" + this._dbName + "'");
Zotero.debug(this._dbPath);