Repository navigation
fix(coderd/x/plugins): back off restarts of a failing plugin - #361
Conversation
RenewPluginLeases renews this replica's leases and returns only id and updated_at, so a renewal reads and decrypts no plugin config. The manager reads a full row with GetPluginByID only when updated_at changed or no runner exists. AcquirePluginLeases now takes only plugins no replica holds, up to the free slots. Bindings of archived chats are kept on purpose: deleting them loses the cursor and the delivered mark, so an unarchived chat would replay its history or move to another link. A test pins that archived chats are not due and keep both. Part of #305.
A plugin whose host process stopped with an error was started again on the next lease interval, every 10 seconds forever, and each start read the module from the database and compiled it again. The runner now keeps its lease and waits 10 seconds after the first failure, doubled for each failure in a row, up to 10 minutes. A runner that stayed up for 5 minutes resets the count, and a changed plugin starts at once. last_error names the delay. Closes #305.
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b94972b5c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A start that took 5 minutes and then failed reset the failure count, so a slow failing load retried every 10 seconds. The window now starts when the module loaded and the runner became ready.
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merged the #360 head (5a2b9d7, which now includes main at 2523de1) into this branch. @codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…backoff # Conflicts: # coderd/x/plugins/manager.go # coderd/x/plugins/manager_internal_test.go
#360 merged, so this PR now targets main. I merged main (29781c8) into this branch. The resulting tree is the same as the reviewed head 9d86f1f: main's tree equals the old #360 head, which this branch already contained. Focused tests pass again under the lock. @codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merged at head Gates on this exact head:
Tests I ran on
Not exercised: a real plugin-host crash on a running server, multi-replica behavior during the backoff (the replica keeps its lease), and the 5 minute uptime reset with a live host (tested through |
Closes #305. This is item 4, restart backoff. It was stacked on #360 (lease renewal), which merged as 29781c8. The base is now
main.Problem
When a plugin's host process stopped with an error, the Manager started it again on the next lease interval. That repeated every 10 seconds forever, and each start read the module from the database (up to 48 MiB) and compiled it again.
Change
failures, the count of earlier runners in a row that stopped with an error. When the runner stops with an error, it setsrestartAt = now + min(10s x 2^failures, 10min)beforedonecloses.Manager.reconcilekeeps the exited runner and its lease untilrestartAt. Then it starts a new runner withfailures + 1.updated_atchanged starts at once, with the count reset.last_errornow readsrestarting in <delay> after: <error>. The delay comes first, so the 2048 byte cut cannot drop it.Tests
All run under
flock ~/.fork-go.lock.TestManagerRestartBackoff(quartz) uses a host that fails at start.GetFileByIDper attempt.last_error: 10s, 20s, 40s, 1m20s.TestRestartDelaychecks the doubling and the 10 minute cap.TestRunnerFailedResetsAfterUptimechecks that only 5 minutes of uptime after ready resets the count.go test -race -count=10 ./coderd/x/plugins/ -run 'TestManager|TestRestartDelay|TestRunnerFailed': 100 PASS.go test -race ./coderd/x/plugins/...: ok.go test ./coderd ./enterprise/coderd -run TestPlugin: ok.golangci-lint run --fix=false ./coderd/x/plugins/...: 0 issues. gofmt clean.Negative controls. Each one makes
TestManagerRestartBackofffail:TestRunnerFailedResetsAfterUptimefails (1m20s, not 10s).TestManagerRestartBackoffgets an extra attempt at 460 s.Not verified
runner.faileddirectly, not with a running host.