Skip to content

[Bug]: t3 doctor cannot delete the pre-0.1.0 database on Windows (EBUSY from its own lock) #24071

Closed

Description

@AkiVonAkira

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. On Windows, have a state.sqlite from before 0.1.0 next to statev2.sqlite in %USERPROFILE%\.t3\userdata.
  2. Stop the server, so nothing else has either database open.
  3. Run t3 doctor and select Delete the database from before 0.1.0.

Expected behavior

Doctor deletes state.sqlite and its -wal and -shm files.

Actual behavior

The step fails with LegacyDatabaseRemoveError caused by EBUSY: resource busy or locked, unlink '...\state.sqlite'. The file stays on disk, and t3 doctor --dry-run keeps offering the repair.

No other process had the file open. Right after doctor exited, [IO.File]::Open(path, 'Open', 'ReadWrite', 'None') on state.sqlite succeeded, and Remove-Item deleted it.

The lock comes from doctor itself. removeLegacyDatabase in apps/server/src/persistence/DatabaseMaintenance.ts runs lockExclusively(legacy), then fs.remove(legacy + suffix), all inside Effect.provide(NodeSqliteClient.layer({ filename: legacy })). The SQLite connection, with locking_mode = EXCLUSIVE, stays open while the file is removed. POSIX allows unlinking an open file, so this works on Linux. Windows refuses, because SQLite does not open the file with FILE_SHARE_DELETE.

On Linux the same repair works. On two Linux machines on the same nightly, the reclaim step and --dry-run behave as expected.

Impact

Minor bug or occasional failure

Version or commit

0.1.3-nightly.20261023.3566. The code is unchanged on main @ 30a405b.

Environment

Windows 11, desktop app T3 Code (Nightly), t3 CLI from t3 update --channel nightly.

Logs or stack traces

Reclaiming database space. This can take several minutes...
Done: 2.85 GiB -> 2.76 GiB, 175 superseded events removed.
ERROR (#2): LegacyDatabaseRemoveError: Could not delete the database from before 0.1.0. Check that this user can write to the data directory.
    at DatabaseMaintenance.removeLegacyDatabase (file:///C:/Users/<user>/.t3/runtime/versions/0.1.3-nightly.20261023.3566/t3.exe:120242:23)
    at runDoctor (file:///C:/Users/<user>/.t3/runtime/versions/0.1.3-nightly.20261023.3566/t3.exe:120253:10)
  [cause]: PlatformError: Busy: FileSystem.remove (C:\Users\<user>\.t3\userdata\state.sqlite)
    [cause]: Error: EBUSY: resource busy or locked, unlink 'C:\Users\<user>\.t3\userdata\state.sqlite'

The error message also points the wrong way. It says to check write permission, but the cause is doctor's own open handle.

Workaround

After doctor exits, delete state.sqlite, state.sqlite-wal, and state.sqlite-shm by hand with the server stopped.

Activity

  1. juliusmarminge commented on Nov 9, 2026

    @juliusmarminge
    Member

    Thanks for the detailed report! #27629 fixes the Windows deletion failure by closing the doctor’s SQLite connection before unlinking, in 1d626d0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions