Skip to content

fix(windows): stop the close crash, apply Safe Mode and keep tabs across Reconnect - #4176

Merged
datlechin merged 3 commits into
mainfrom
fix/audit-wave-2-windows
Nov 10, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/audit-wave-2-windows

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

Fixes from the 2026-11-10 code audit (wave 2) for the Windows app and the shared core.

Windows app

  • Closing a tab, or disconnecting, while its query or table page loads no longer crashes: the tab cancels its run, waits for it, then frees the run, editor and session. A disposed run makes no native call.
  • Safe Mode is applied. Before a typed run the core judges each statement at the connection's level (DatabaseSession.gate_run, over SafeModeLevel::gate): Confirm writes asks before any write, Off before a DROP, TRUNCATE, or an unfiltered DELETE or UPDATE. The dialog lists each statement, or the whole text when it reads stricter than every batch. Read only refuses the run. MySQL DELIMITER scripts are judged per statement.
  • A Safe Mode change applies at once to every open session of that connection (DatabaseSession.set_safe_mode). A change to Read only that the user declines to reconnect for applies Confirm writes until the next connect, with a bar saying so.
  • Reconnect, Disconnect and connecting an edited connection ask about held transactions first. Reconnect and an edited connection bring the tabs back with their SQL and keep the closed-tab list; cancelling the connect keeps them.
  • Every dialog goes through one guard, so a second dialog in another window reads as Cancel instead of throwing out of async void.
  • One process owns a data folder: Program.Main registers it with AppInstance.FindOrRegisterForKey, and a second launch hands its activation over and exits. The hand-over is bounded at 5 s and retried, a null owner or a failed setup starts normally, and the key is released after the session is saved.

Core

  • ConnectionStore re-reads connections.json before every write and holds a lock file beside it, so a second process, a hand edit or a synced file is no longer overwritten from a stale cache. A lock the file system refuses (NFS, SMB) logs a warning and the write goes ahead on the re-read alone. A file broken by hand after loading blocks writes instead of being overwritten.
  • ClickHouse: a login whose profile sets readonly=1 connects. The login request carries no setting and asks system.settings which of the driver's settings this login may change; later requests send only those. At level 1 a read-only connection still sends readonly=1, which undoes a session's SET readonly = 0. NaN or Inf in a non-Nullable Float column reads as out of range, never NULL. A login that cannot change a pinned mutations_sync=0 is refused a mutation rather than told it saved. Decimals keep their scale.
  • Session::grammar keeps the grammar of the engine it opened on, so the Safe Mode gate on Windows and the Linux editor's statement split use it while the link is down, instead of PostgreSQL's.

Tests changed on purpose

  • client_factory::tests::a_login_with_a_readonly_level_of_its_own_keeps_it, no_read_asks_a_login_at_its_own_level_for_another, a_read_only_connection_asks_a_login_at_readonly_1_for_no_setting (replaced): readonly and allow_ddl at level 1.
  • endpoint::tests::a_login_answer_reads_as_the_version_the_database_and_the_readonly_level, a_login_at_readonly_1_that_may_change_nothing_is_sent_only_its_own_level: the login query reads more columns.
  • cell_seed::tests::numbers_keep_every_digit_quoted_or_bare: decimals carry their scale.

Known gap

  • A relaunch whose redirect lands in the sub-millisecond window between the owner's ShutDown and its window's Closed opens nothing. Releasing the key earlier would let two processes write session.json.

Test plan

  • Rust: tablepro-storage 337, tablepro-session 153, tablepro-driver-clickhouse 142 unit, tablepro-ffi 97, all passing; clippy and rustfmt clean.
  • ClickHouse integration on Docker: 93 of 96 pass, including the new restricted_logins suite (readonly=1 with and without changeable settings, mutations_sync pinned at 0, a lifted readonly level put back). The 3 that fail on macOS (two TLS cases expecting Linux's verifier errors, the million-row export reading a cgroup file) touch no changed code; the Linux CI job runs them.
  • .NET solution on macOS: 253 passing, bindings regenerated and matching the library. TablePro.App and its UI tests (including new close-while-running and Reconnect tests) build and run only on the Windows runners.
  • Reviewed in four rounds by Claude agents that did not write the change.

@datlechin
datlechin merged commit 7565a1e into main Nov 10, 2026
46 checks passed
@datlechin
datlechin deleted the fix/audit-wave-2-windows branch November 10, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant