Skip to content

Fixes on top of v0.7.2 - #7

Closed
CorentinFelten wants to merge 11 commits into
masterfrom
fix/v0.7.2-fixes
Closed

CorentinFelten wants to merge 11 commits into
masterfrom
fix/v0.7.2-fixes

Conversation

@CorentinFelten

Copy link
Copy Markdown
Owner

Ten fixes on top of v0.7.2, one commit each:

  • Default deployment_max_extensions to 3, as documented (the code used 4)
  • Terminate expired deployments without Redis (they were only marked as errors)
  • Recover from panics in request handlers (500 + logged stack trace instead of a dropped connection)
  • List the deployed challenges in the /admin/deploy-all response (entries were empty); empty bulk lists are [], not null
  • Refuse to extend a deployment that is not running
  • tcp playbook: no longer requires traefik_network, which TCP services never join
  • Valid default command in the Docker image (serve --port 8080 --config data/config.yaml)
  • Honor max_concurrent_ansible without Redis, for team requests and expiries only (admin actions are not limited)
  • Remove the unused test constant
  • Port bindings store: one connection pool per database instead of a leaked one per call

Notes for review:

  • Panic recovery had been commented out since the first commit, with no explanation in the history; nothing in Galvanize panics on purpose, and the tests show the only change is a 500 response instead of a dropped connection.
  • Not changed: the main database's _busy_timeout/_journal_mode=WAL parameters (pkg/db.go) are ignored by the glebarez driver, so WAL is off. The busy timeout is still 5s, the driver's default. Enabling WAL would change how backups must be restored (-wal/-shm files), so it is left for a separate decision.

config.example.yaml documents a default of 3 extensions per deployment,
but cmd/root.go set 4, so a config without the key allowed one more
extension than documented.
Without a job queue, the expiry scheduler marked each expired
deployment as an error ("no job queue configured for termination")
and left its containers running, while the API's own terminate
endpoint already terminates in place in that case.

ExpiryScheduler.WithDirectTermination gives the scheduler the
challenge index, config provider and deployer it needs, and serve sets
it when Redis is not configured: expired deployments are then
terminated with models.TerminateDeployment, as the API does, which
marks them as errors only if the termination fails.
middleware.Recover was commented out since the first commit, with no
note on why. Without it, net/http recovers a panicking handler itself
but drops the connection without a response, and the request logger
never logs the request. Nothing in Galvanize panics or recovers on
purpose, so enabling it changes nothing else.

The middleware setup moves to useMiddleware, so it can be tested.
Recover logs the panic and its stack trace through zap, and the
request logger then logs the 500 response.
DeployAllAdminInstances appended an empty ChallengeCategoryResponse for
each challenge it deployed, so its challenges list held one
{"category": "", "challenge_name": ""} per challenge. It now holds
each one's category and name, as TerminateAllAdminInstances already
does. Zync only reads challenges_count, so it is unaffected.

Both endpoints also returned "challenges": null when there was
nothing to do, although the API spec requires an array: they now
return [].
ExtendDeploymentExpiration only checked the expiry, the extension
window and the extensions left, so a deployment still starting, being
stopped or failed could be extended, using up an extension, and
ExtendInstance answered with status running regardless.

It now returns ErrNotRunning first for any deployment not running,
which ExtendInstance answers with a 400 like the other refusals and
counts as not_running in the extension rejection metric.
The tcp playbook's compose definition declared traefik_network as an
external network, but the TCP service runs with network_mode: bridge
and publishes its ports, so it never joins it. Ansible failed with
"'traefik_network' is undefined" when the parameter was not set, and
TCP challenges do not need Traefik.

Checked by rendering the compose definition with and without
traefik_network and validating it with docker compose config. Instances
deployed by the previous playbook still terminate: the network was
external, so compose never created or removed it.
The Dockerfile's CMD ran `galvanize serve 8080 -c config.yaml`, but
serve takes no arguments (cobra.NoArgs) and reads the port from
--port, so the container exited with 'unknown command "8080" for
"galvanize serve"' unless a command was given, as docker-compose.yml
does.

The default is now the same command as docker-compose.yml's:
serve --port 8080 --config data/config.yaml.
max_concurrent_ansible is documented as the cap on concurrent Ansible
runs without Redis (default 5), but nothing read it: each team deploy
or terminate, and now each expiry, started its own unbounded run.

ansible.LimitedDeployer wraps a Deployer with a fixed number of slots
shared by Deploy and Terminate; further calls wait for a slot, or for
their context. Without Redis, serve gives one with
max_concurrent_ansible slots to the server, as ServerOpts.TeamDeployer
for team requests, and to the expiry scheduler. Admin actions keep the
unlimited deployer, so they are never queued behind team requests.
With Redis, num_workers bounds these runs as before.
constants.go declared test = 123, used nowhere.
openPortBindingDB opened a new gorm connection pool, and ran
AutoMigrate, on each of its calls: loading, reserving, saving and
clearing bindings, i.e. several times per deploy and terminate. None
was ever closed, so each call left a SQLite connection and its file
descriptor open: 200 calls left 200 more descriptors open.

The store now keeps one pool per database file, opened and migrated on
first use, in a map guarded by portBindingDBMu, which every caller
already holds.

Checked while looking into it: these connections did not lack a busy
timeout, as suspected; the glebarez driver sets busy_timeout to 5000
by default.
Coverage of the lines changed by these fixes showed what no test ran:

- serve's choice of execution without Redis. It moves to
  configureQueueless, tested with and without a job queue: without
  one, team requests and expiries share one LimitedDeployer with
  max_concurrent_ansible slots (default 5); with one, nothing changes.
  ExpiryScheduler.DirectTerminationDeployer and LimitedDeployer.Limit
  expose what the tests check.
- The config defaults, including deployment_max_extensions: 3. They
  move to setConfigDefaults, tested by loading a config that omits
  them.
- A terminate call that gives up waiting for a slot, and a port
  bindings store that cannot be opened or migrated, which must not be
  cached.

The lines changed by these fixes go from 61% to 74% covered; the rest
are the calls in serve and initConfig, which only run at startup.
@CorentinFelten
CorentinFelten deleted the fix/v0.7.2-fixes branch October 2, 2026 00:20
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