@@ -1379,6 +1379,11 @@ func (db *DB) writeWALHeader(ctx context.Context, f *os.File, data []byte, offse
1379
1379
return fmt .Errorf ("WAL header write must be 32 bytes in size, received %d" , len (data ))
1380
1380
}
1381
1381
1382
+ // Prevent transactions when the write lock has not been acquired (e.g. EXCLUSIVE lock)
1383
+ if db .writeLock .State () != RWMutexStateExclusive {
1384
+ return fmt .Errorf ("cannot write to WAL header without WRITE lock, exclusive locking not allowed" )
1385
+ }
1386
+
1382
1387
// Determine byte order of checksums.
1383
1388
switch magic := binary .BigEndian .Uint32 (data [0 :]); magic {
1384
1389
case 0x377f0682 :
@@ -1427,6 +1432,11 @@ func (db *DB) writeWALFrameHeader(ctx context.Context, f *os.File, data []byte,
1427
1432
}
1428
1433
}()
1429
1434
1435
+ // Prevent transactions when the write lock has not been acquired (e.g. EXCLUSIVE lock)
1436
+ if db .writeLock .State () != RWMutexStateExclusive {
1437
+ return fmt .Errorf ("cannot write to WAL frame header without WRITE lock, exclusive locking not allowed" )
1438
+ }
1439
+
1430
1440
// Prevent SQLite from writing before the current WAL position.
1431
1441
if offset < db .wal .offset {
1432
1442
return fmt .Errorf ("cannot write wal frame header @%d before current WAL position @%d" , offset , db .wal .offset )
@@ -1442,6 +1452,11 @@ func (db *DB) writeWALFrameData(ctx context.Context, f *os.File, data []byte, of
1442
1452
TraceLog .Printf ("[WriteWALFrameData(%s)]: offset=%d size=%d owner=%d %s" , db .name , offset , len (data ), owner , errorKeyValue (err ))
1443
1453
}()
1444
1454
1455
+ // Prevent transactions when the write lock has not been acquired (e.g. EXCLUSIVE lock)
1456
+ if db .writeLock .State () != RWMutexStateExclusive {
1457
+ return fmt .Errorf ("cannot write to WAL frame data without WRITE lock, exclusive locking not allowed" )
1458
+ }
1459
+
1445
1460
// Prevent SQLite from writing before the current WAL position.
1446
1461
if offset < db .wal .offset {
1447
1462
return fmt .Errorf ("cannot write wal frame data @%d before current WAL position @%d" , offset , db .wal .offset )
0 commit comments