Skip to content

fix(db_init.sh): resolve services id dynamically — fixes 503 "unable to get a node" on fresh deployments - #23

Open
tmiland-labs wants to merge 1 commit into
porelli:mainfrom
tmiland-labs:fix/db-init-service-id
Open

fix(db_init.sh): resolve services id dynamically — fixes 503 "unable to get a node" on fresh deployments#23
tmiland-labs wants to merge 1 commit into
porelli:mainfrom
tmiland-labs:fix/db-init-service-id

Conversation

@tmiland-labs

Copy link
Copy Markdown

Problem

Since syncstorage-rs 0.21.1 (tokenserver-mysql), the tokenserver resolves the sync service by name and then matches nodes.service against that id:

  • get_service_id: SELECT id FROM services WHERE service = 'sync-1.5'
  • get_best_node: SELECT id, node FROM nodes WHERE service = ? ... (tokenserver-mysql/src/db/db_impl.rs)

The upstream migration chain guarantees that sync-1.5 does not have id 1 on a fresh database:

  1. 2021-08-03 populate_services inserts sync-1.1 (id 1) and sync-1.5 (id 2)
  2. 2021-12-22 remove_services deletes the rows (AUTO_INCREMENT counter is not reset)
  3. 2026-02-26 add_sync15_service re-inserts sync-1.5 — it lands on id 3

db_init.sh hardcodes nodes.service = '1', so the node row never matches and every login fails with 503 "Unexpected error: unable to get a node" on current images. Verified on a completely fresh stack (docker compose down -v && up): services shows sync-1.5 at id 3 while the seeded nodes row points at service 1.

Fix

  • Look up the services id by name when inserting the node row
  • Make the nodes upsert self-healing: ON DUPLICATE KEY UPDATE also refreshes service, which repairs databases initialized by the old script
  • Replace the explicit-id INSERT IGNORE with a name-based guard so duplicate sync-1.5 rows can't be created
  • Fix pre-existing shellcheck SC2086/SC2006 findings (quoting, $( ))

Verification

  • Tested against MariaDB with drifted / fresh / duplicate-name database states (script is idempotent across restarts)
  • Confirmed working end-to-end with Firefox against syncstorage-rs 0.21.1-based images: login + sync succeed, services.id == nodes.service consistent after init

…rvice=1

syncstorage-rs >= 0.21.1 tokenserver resolves the node via
services.id (get_service_id) and get_best_node matches
nodes.service against it. Upstream migrations leave sync-1.5
at id 3 (populate_services seeds ids 1-2, remove_services
clears rows, add_sync15_service re-inserts with the
auto-increment counter unchanged), so the hardcoded service=1
never matches and logins fail with 503 'unable to get a node'.

- look up the services id by name when inserting the node row
- make the nodes upsert self-healing (also refreshes service)
- replace INSERT IGNORE by name to avoid duplicate sync-1.5 rows
- fix pre-existing SC2086/SC2006 shellcheck findings
tmiland pushed a commit to tmiland/firefox-sync that referenced this pull request Sep 8, 2026
Documents the two fixes carried by this fork (upstream PRs porelli#23 and porelli#24)
and points deployers at the production-tested MySQL images on
ghcr.io/tmiland/firefox-sync.
tmiland pushed a commit to tmiland/firefox-sync that referenced this pull request Sep 8, 2026
- Lead with what the fork carries: db_init fix (upstream porelli#23), 0.23
  build-args (upstream porelli#24), production images on ghcr.io/tmiland
- Add architecture table (embedded tokenserver since 0.23, dual MariaDB,
  one-shot init), images section, troubleshooting section
- Keep upstream wording for disclaimer/security/background/browser setup,
  credit porelli, Mozilla and jeena; note GPL-3.0
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