@@ -1412,8 +1412,8 @@ export class ActorInstance<
14121412 // Every actor gets its own SqliteVfs/@rivetkit /sqlite instance. The async
14131413 // @rivetkit /sqlite build is not re-entrant, and sharing one instance across
14141414 // actors can cause cross-actor contention and runtime corruption.
1415- if ( ! this . #sqliteVfs && this . driver . getSqliteVfs ) {
1416- this . #sqliteVfs = await this . driver . getSqliteVfs ( ) ;
1415+ if ( ! this . #sqliteVfs && this . driver . createSqliteVfs ) {
1416+ this . #sqliteVfs = await this . driver . createSqliteVfs ( ) ;
14171417 }
14181418
14191419 client = await this . #config. db . createClient ( {
@@ -1446,6 +1446,16 @@ export class ActorInstance<
14461446 } ) ;
14471447 }
14481448 }
1449+ if ( this . #sqliteVfs) {
1450+ try {
1451+ await this . #sqliteVfs. destroy ( ) ;
1452+ } catch ( cleanupError ) {
1453+ this . #rLog. error ( {
1454+ msg : "sqlite vfs teardown after setup failure failed" ,
1455+ error : stringifyError ( cleanupError ) ,
1456+ } ) ;
1457+ }
1458+ }
14491459 this . #sqliteVfs = undefined ;
14501460 if ( error instanceof Error ) {
14511461 this . #rLog. error ( {
@@ -1466,23 +1476,31 @@ export class ActorInstance<
14661476
14671477 async #cleanupDatabase( ) {
14681478 const client = this . #db;
1479+ const sqliteVfs = this . #sqliteVfs;
1480+ const dbConfig = "db" in this . #config ? this . #config. db : undefined ;
14691481 this . #db = undefined ;
14701482 this . #sqliteVfs = undefined ;
14711483
1472- if ( ! client ) {
1473- return ;
1474- }
1475- if ( ! ( "db" in this . #config) || ! this . #config. db ) {
1476- return ;
1484+ if ( client && dbConfig ) {
1485+ try {
1486+ await dbConfig . onDestroy ?.( client ) ;
1487+ } catch ( error ) {
1488+ this . #rLog. error ( {
1489+ msg : "database cleanup failed" ,
1490+ error : stringifyError ( error ) ,
1491+ } ) ;
1492+ }
14771493 }
14781494
1479- try {
1480- await this . #config. db . onDestroy ?.( client ) ;
1481- } catch ( error ) {
1482- this . #rLog. error ( {
1483- msg : "database cleanup failed" ,
1484- error : stringifyError ( error ) ,
1485- } ) ;
1495+ if ( sqliteVfs ) {
1496+ try {
1497+ await sqliteVfs . destroy ( ) ;
1498+ } catch ( error ) {
1499+ this . #rLog. error ( {
1500+ msg : "sqlite vfs cleanup failed" ,
1501+ error : stringifyError ( error ) ,
1502+ } ) ;
1503+ }
14861504 }
14871505 }
14881506
0 commit comments