diff --git a/hgext/sqlitestore.py b/hgext/sqlitestore.py --- a/hgext/sqlitestore.py +++ b/hgext/sqlitestore.py @@ -76,6 +76,7 @@ ) from mercurial.utils import ( interfaceutil, + procutil, storageutil, ) @@ -1005,17 +1006,18 @@ @property def _dbconn(self): - # SQLite connections can only be used on the thread that created - # them. In most cases, this "just works." However, hgweb uses - # multiple threads. - tid = threading.current_thread().ident + # SQLite connections can only be used on the OS and Python thread that + # created them. In most cases, this "just works." However, hgweb uses + # multiple Python threads. And Mercurial may fork. So we need to check + # global state before returning an existing connection. + key = (procutil.getpid(), threading.current_thread().ident) if self._db: - if self._db[0] == tid: + if self._db[0] == key: return self._db[1] db = makedb(self.svfs.join('db.sqlite')) - self._db = (tid, db) + self._db = (key, db) return db