Skip to content

Commit e5e2ecf

Browse files
n1hilityclaude
andcommitted
fix(server): clarify the SQLite WAL switch and its failure mode
Reword the durability helper's comment to match sqlx's actual behaviour (pool connections open one at a time; the WAL switch waits out busy_timeout before failing), report a WAL switch failure with the file path and the exclusive-access requirement, and note in the Helm values and reference docs that the SQLite file needs a local block-backed volume. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
1 parent 501c80f commit e5e2ecf

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

‎crates/openshell-server/src/persistence/sqlite.rs‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ pub(super) async fn replace_pool_connection(store: &SqliteStore) -> PersistenceR
5959
/// durability guarantees use the Postgres backend.
6060
///
6161
/// `journal_mode=WAL` is persistent in the database file, but switching into
62-
/// it takes an exclusive lock that `busy_timeout` cannot wait for. The pool
63-
/// opens `min_connections` eagerly and concurrently, so the switch happens
64-
/// here on a single connection first; the pool connections then find the file
65-
/// already in WAL mode. `synchronous` is a per-connection setting and is
66-
/// applied through the options on every connection.
62+
/// it needs exclusive access: if another connection holds the file open, the
63+
/// switch waits out `busy_timeout` and then fails. Doing it up front on one
64+
/// connection means the pool connections only ever re-apply the pragma to a
65+
/// file that is already in WAL mode, which never blocks, and a failure
66+
/// surfaces as a single clear connect error instead of a pool error later.
67+
/// The first start after upgrading a rollback-journal database therefore needs
68+
/// the file to be otherwise unopened. `synchronous` is a per-connection
69+
/// setting and is applied through the options on every connection.
6770
///
6871
/// In-memory databases are left on their defaults: WAL is meaningless there
6972
/// and the shared-cache keepalive connection already provides their lifetime
@@ -74,10 +77,18 @@ async fn configure_on_disk_durability(
7477
let options = options
7578
.journal_mode(SqliteJournalMode::Wal)
7679
.synchronous(SqliteSynchronous::Normal);
80+
let wal_error = |e: &sqlx::Error| {
81+
PersistenceError::Database(format!(
82+
"failed to switch SQLite database {} to WAL journal mode (the switch needs \
83+
exclusive access; close other connections to the file and retry): {}",
84+
options.get_filename().display(),
85+
map_db_error(e)
86+
))
87+
};
7788
let connection = SqliteConnection::connect_with(&options)
7889
.await
79-
.map_err(|e| map_db_error(&e))?;
80-
connection.close().await.map_err(|e| map_db_error(&e))?;
90+
.map_err(|e| wal_error(&e))?;
91+
connection.close().await.map_err(|e| wal_error(&e))?;
8192
Ok(options)
8293
}
8394

‎deploy/helm/openshell/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ discovery endpoint or its TLS CA.
247247
| server.credentialDrivers.vault.timeoutSecs | string | `""` | HTTP request timeout in seconds. Empty = driver default. |
248248
| server.credentialDrivers.vault.tokenPath | string | `""` | Mounted token file path when authMethod is token_file. |
249249
| server.credentialStorage.existingSecret | string | `""` | Name of a pre-existing Secret containing the key-encryption key. When set, the chart does NOT generate a new Secret; it references this one instead. The Secret must contain a key named "key-encryption-key" with a base64-encoded 32-byte value. Required for GitOps workflows that render manifests with `helm template` (where `lookup` is unavailable). |
250-
| server.dbUrl | string | `"sqlite:/var/openshell/openshell.db"` | Gateway database URL (used for the default SQLite backend). |
250+
| server.dbUrl | string | `"sqlite:/var/openshell/openshell.db"` | Gateway database URL (used for the default SQLite backend). SQLite runs in WAL mode and needs a local block-backed volume, not NFS or other network filesystems. |
251251
| server.defaultRuntimeClassName | string | `""` | Default Kubernetes runtimeClassName for sandbox pods. Applied when a CreateSandbox request does not specify one. Empty (default) = omit the field, using the cluster's default RuntimeClass. Set to a RuntimeClass name (e.g. "kata-containers", "nvidia") to apply it to all sandboxes that don't explicitly override it. |
252252
| server.disableTls | bool | `false` | Disable TLS entirely - the server listens on plaintext HTTP. Set to true when a reverse proxy / tunnel terminates TLS at the edge. |
253253
| server.drivers.kubernetes.operatorNamespaceFile | string | `""` | Path to a JSON file containing an array of namespace names allowed in operator mode. Hot-reloaded on change. |

‎deploy/helm/openshell/values.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ server:
215215
# -- Namespace where sandbox pods are created. Defaults to the Helm release
216216
# namespace (.Release.Namespace) when left empty.
217217
sandboxNamespace: ""
218-
# -- Gateway database URL (used for the default SQLite backend).
218+
# -- Gateway database URL (used for the default SQLite backend). SQLite runs
219+
# in WAL mode and needs a local block-backed volume, not NFS or other network
220+
# filesystems.
219221
dbUrl: "sqlite:/var/openshell/openshell.db"
220222
# -- Name of a pre-existing Opaque Secret containing a PostgreSQL
221223
# connection URI (key: uri). When set, the gateway reads OPENSHELL_DB_URL

‎docs/reference/gateway-config.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gateway CLI flag > gateway OPENSHELL_* env var > TOML file > built-in defa
1818

1919
`database_url` is env-only. The loader rejects it when it appears in the file. When `OPENSHELL_DB_URL` is unset, the gateway stores its SQLite database under `$XDG_STATE_HOME/openshell/gateway/openshell.db`.
2020

21-
SQLite databases run in WAL mode with `synchronous=NORMAL`: the gateway keeps `openshell.db-wal` and `openshell.db-shm` next to the database file, the file must live on a local filesystem, and a backup must use `sqlite3 openshell.db ".backup <copy>"` rather than copying `openshell.db` on its own. A power loss can roll back the most recent transactions without corrupting the database.
21+
On-disk SQLite databases run in WAL mode with `synchronous=NORMAL`: the gateway keeps `openshell.db-wal` and `openshell.db-shm` next to the database file, the file must live on a local filesystem, and a backup must use `sqlite3 openshell.db ".backup <copy>"` rather than copying `openshell.db` on its own. A power loss can roll back the most recent transactions without corrupting the database.
2222

2323
`name` assigns an operator-facing identity to the gateway installation. Set it with `[openshell.gateway].name`, `--name`, or `OPENSHELL_GATEWAY_NAME`. It defaults to `openshell`; the Helm chart defaults it to the chart fullname so all replicas in one installation share a name. Chart fullnames are only unique within their Kubernetes namespace, so set `server.name` explicitly when one collector receives telemetry from multiple namespaces or clusters. This identity is independent of client-side gateway aliases, TLS names, and `gateway_jwt.gateway_id`.
2424

0 commit comments

Comments
 (0)