Conversation
…top suite hang npm test / c8 mocha finished all tests but hung for several extra minutes before the process actually exited, because: - getFetch() in src/fetch-utils.js caches a keep-alive @adobe/fetch context that is never reset() in tests, leaving open sockets that keep the event loop alive. - An ad-hoc h1NoCache() fetch context in the http-proxy test and a module-level one in import-cmd.test.js were never reset either. - Several da-auth.test.js tests exercised the real OAuth login flow (waitForToken in src/content/da-auth.js), which starts a real 5-minute setTimeout safety timer that is only cleared once a /token callback request arrives. The mocked HTTP server never simulated that callback (or raced it against an uncancelled 100ms timeout), so the timer kept the process alive for up to 5 minutes after mocha reported all tests passing. Fixes: - test/setup-env.js: add a global mochaHooks.afterAll that calls resetContext() to close the shared getFetch() keep-alive context. - test/server.test.js: reuse a single h1NoCache() context for the proxy test and reset() it in the finally block. - test/import-cmd.test.js: reset() the module-level fetch context after all tests in the file. - test/content/da-auth.test.js: mock the HTTP callback server to simulate an immediate /token success so waitForToken() resolves and clears its timer deterministically, instead of leaking it. Verified: npx mocha and npm test now both exit on their own right after reporting results (548 passing), instead of hanging for minutes afterwards. Co-authored-by: Copilot <[email protected]>
kptdobe
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure your pull request adheres to the following guidelines:
Related Issues
N/A — found while investigating a reported hang at the end of
npm test.Summary
npm test(c8 mocha) ran all tests successfully but the process kept running for several extra minutes after mocha reported the final "passing" summary, before finally exiting. Root cause: multiple leaked async resources kept the Node event loop alive.Leaked
@adobe/fetchkeep-alive contextsgetFetch()insrc/fetch-utils.jslazily creates and caches akeepAlive()fetch context (an open-socket connection pool). Production code paths always callresetContext()on shutdown, but no test ever did, so the shared context (used acrosstest/server.test.js,test/up-cmd.test.js,test/utils.js) stayed open for the whole run.h1NoCache()context created per-request inside the http-proxy test intest/server.test.jswas never reset.h1NoCache()context intest/import-cmd.test.jswas never reset.Leaked OAuth callback timer
waitForToken()insrc/content/da-auth.jsstarts a real 5-minutesetTimeoutsafety timer that is only cleared once a/tokencallback request arrives on its local HTTP server.test/content/da-auth.test.jsmocked that HTTP server as a no-op (or raced the real flow against an uncancelled 100ms timeout viaPromise.race), so the callback never fired and the 5-minute timer kept running in the background — exactly matching the observed multi-minute delay before process exit.Fix
test/setup-env.js: added a globalmochaHooks.afterAllhook that callsresetContext()to close the sharedgetFetch()context after the whole suite runs.test/server.test.js: reuse a singleh1NoCache()context for the http-proxy test andreset()it in thefinallyblock.test/import-cmd.test.js:reset()the module-level fetch context in anafter()hook.test/content/da-auth.test.js: mock the HTTP callback server to simulate an immediate/tokensuccess response sowaitForToken()resolves and clears its timer deterministically, instead of leaking it for up to 5 minutes. Removed the now-unnecessaryPromise.race/timeout workaround.Verification
npx mochaandnpm test(c8 mocha) both now exit on their own immediately after reporting results (548 passing), instead of hanging for several extra minutes.process._getActiveHandles()/ timer-tracing instrumentation inside the actual mocha worker process that all previously-leaked sockets/timers are now properly closed/cleared.npx eslintpasses on all changed files.Thanks for contributing!