Skip to content

Apply a route switch in one Caddy configuration load #438

In progress

Description

@samuelmbabhazi

Problem

caddy.Client.ApplyRoute changes Caddy's configuration twice for one route change: the route itself (PATCH /id/<route> or POST …/routes), then the plain-HTTP hosts (SetPlainHosts). Caddy applies each change as a full reload. At each reload, its previous HTTP server:

  • finishes the requests in flight;
  • closes the idle keep-alive connections at once.

A client that sends a request on one of them at that instant gets a reset, as #437 found. Caddy's log of the failed run shows the two loads 1 ms apart.

Proposal

Apply a switch as one change, in one admin request. For example, replace the server's routes and automatic_https.skip together, or the whole HTTP app configuration under an If-Match precondition. This halves the moments at which idle connections are closed. It also removes the window between the two writes, in which the route and the plain hosts disagree.

Acceptance

  • One configuration load per UpsertRoute and per RemoveRoute, checked in the real Caddy test by counting the autosaved config lines, or through the admin API.
  • The existing guarantees hold: a failed write leaves every host reachable, and the order is kept.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions