Skip to content

fix(daemon): stop ResourceManager upon Test completion to prevent resource leaks - #2571

Open
Tyagiquamar wants to merge 1 commit into
encoredev:mainfrom
Tyagiquamar:fix/daemon-resource-manager-stop-on-test
Open

Tyagiquamar wants to merge 1 commit into
encoredev:mainfrom
Tyagiquamar:fix/daemon-resource-manager-stop-on-test

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Sep 5, 2026

Copy link
Copy Markdown

Problem

When encore test is executed, Manager.Test() calls mgr.testSpec() which initializes a new infra.ResourceManager via infra.NewResourceManager(..., forTests: true) and calls rm.StartRequiredServices(jobs, parse.Meta) to boot ephemeral test infrastructure (such as local NSQ pubsub daemons or local redis).

Unlike ExecScript (which defers rm.StopAll()) and Run.Stop() (which terminates its resource manager), Manager.Test() did not capture or stop the ResourceManager after test execution finished or failed.

As a result, long-running daemon processes leak child processes (nsqd, miniredis) and file descriptors across repeated test runs.

Solution

  1. Update mgr.testSpec() to return (*builder.TestSpecResult, *infra.ResourceManager, error).
  2. Add defer rm.StopAll() in Manager.Test() once the test execution finishes or errors out.
  3. Clean up rm.StopAll() in testSpec error return paths (jobs.Wait(), ServiceConfigs, ForTests, TestSpec).

Verification

  • Verified go vet ./cli/daemon/run/... runs cleanly.
  • Code mirrors existing lifecycle pattern in cli/daemon/run/exec_script.go:69.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@Tyagiquamar

Copy link
Copy Markdown
Author

Hi, friendly ping for review on this PR when you have a moment. Happy to address any feedback. Thanks!

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