Skip to content

fix: gate MariaDBManager.start() on is_running() to prevent double-start errors#12

Open
amitascra wants to merge 1 commit into
frappe:mainfrom
amitascra:fix/mariadb-start-guard
Open

fix: gate MariaDBManager.start() on is_running() to prevent double-start errors#12
amitascra wants to merge 1 commit into
frappe:mainfrom
amitascra:fix/mariadb-start-guard

Conversation

@amitascra
Copy link
Copy Markdown

Problem

MariaDBManager.start() unconditionally calls brew services start (macOS) or systemctl start mariadb (Linux), even when MariaDB is already running. This causes bench init to fail at step 2 with a port-conflict error when MariaDB is running via Docker, remote host, or an already-started brew service:

Bootstrap failed: 5: Input/output error Error: Failure while executing; /bin/launchctl bootstrap gui/501 .../homebrew.mxcl.mariadb.plist exited with 5.

Fixes #3

Solution

  • Added is_running(): Probes the configured host:port via a stdlib TCP socket (socket.create_connection with 1s timeout). Works for local, Docker, and remote MariaDB instances. No new dependencies (project remains zero-dependency).
  • Gated start(): Returns early if MariaDB is already accepting connections on the configured host/port.

Testing

Added comprehensive unit tests in tests/test_mariadb_manager.py:

  • is_running() returns True when port is open, False on connection refused or timeout
  • is_running() respects the configured host and port from bench.toml
  • start() skips the service call when MariaDB is already running
  • start() correctly calls brew services start (default and versioned) on macOS
  • start() correctly calls systemctl start mariadb on Linux

All 8 new tests pass. No regressions in existing tests.

MariaDBManager.start() was running brew services start / systemctl start
unconditionally. When MariaDB is already running (Docker, remote, or a
brew service that's already started), this caused a port-conflict crash:

  Bootstrap failed: 5: Input/output error
  Error: Failure while executing; `/bin/launchctl bootstrap gui/501
  .../homebrew.mxcl.mariadb.plist` exited with 5.

Fix:
- Add is_running() using a stdlib TCP probe (socket.create_connection)
  so no new dependencies are introduced (project is zero-dependency).
- Gate start() on is_running(): return early if the configured
  host:port is already accepting connections.

Fixes frappe#3
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.

MariaDBManager.start() unconditionally runs brew services start, breaking init when MariaDB is already running (Docker/remote)

1 participant