As of #11466 we no longer have any logic to prevent a user from opening a wallet twice in two instances simultaneously. Not only could this break BDB (without the -privdb=false option, which I have really no idea why we even have a tuneable option for that), but we certainly don't have logic to handle such a case gracefully. It was noted in the original PR's description, but somehow was never followed up on before merge.
DbMpoolFile* mpf = pdb_temp->get_mpf();
                ret = mpf->set_flags(DB_MPOOL_NOFILE, 1);
                if (ret != 0) {
                    throw std::runtime_error(strprintf("CDB: Failed to configure for no temp file backing for database %s", strFilename));
                }
            }
            ret = pdb_temp->open(nullptr,                             
                            fMockDb ? nullptr : strFilename.c_str(),  
                            fMockDb ? strFilename.c_str() : "main",   
                            DB_BTREE,                                 
                            nFlags,                                   
                            0);
            if (ret != 0) {
                throw std::runtime_error(strprintf("CDB: Error %d, can't open database %s", ret, strFilename));
            }
            CheckUniqueFileid(*env, strFilename, *pdb_temp);
            pdb = pdb_temp.release();
            env->mapDb[strFilename] = pdb;
            if (fCreate && !Exists(std::string("version"))) {
                bool fTmp = fReadOnly;
                fReadOnly = false;
                WriteVersion(CLIENT_VERSION);
                fReadOnly = fTmp;
            }
        }
        ++env->mapFileUseCount[strFilename];
        strFile = strFilename;
    }
}
void CDB::Flush()