Skip to content

fix(@redhat-cloud-services/frontend-components-config): clean up properly with CTRL+C - #2397

Merged
charlesmulder merged 2 commits into
RedHatInsights:masterfrom
adonispuente:cleanup
Aug 5, 2026
Merged

fix(@redhat-cloud-services/frontend-components-config): clean up properly with CTRL+C#2397
charlesmulder merged 2 commits into
RedHatInsights:masterfrom
adonispuente:cleanup

Conversation

@adonispuente

@adonispuente adonispuente commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Theres an issue in the dev-proxy script where when trying to kill the terminal with CTRL+C, it hangs up and doesnt clean up properly. This just fixes that

Summary by CodeRabbit

  • Bug Fixes
    • Improved development proxy shutdown handling for interrupt and termination signals, ensuring a consistent exit flow.
    • Ensures spawned processes and proxy-related containers are properly stopped and removed before exit, including the optional Chrome container.
    • Proxy and Chrome containers now clean themselves up automatically when they stop.
    • Concurrent process failures now exit with a failure status instead of appearing successful.

@adonispuente
adonispuente requested a review from a team as a code owner July 27, 2026 20:13
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Walkthrough

The development proxy scripts now recursively terminate child processes, remove proxy and Chrome containers during cleanup, handle termination signals, and return a failure status when concurrent processes fail.

Changes

Development proxy shutdown and container lifecycle

Layer / File(s) Summary
Recursive process cleanup
packages/config/src/bin/dev-proxy-script.ts
The script replaces tree-kill with recursive pgrep-based termination. Cleanup uses this process-tree termination and handles missing or already-terminated processes.
Container cleanup and failure handling
packages/config/src/bin/dev-proxy-script.ts, packages/config/src/bin/serve-chrome.ts
Proxy and Chrome containers use --rm. Signal handlers run cleanup before exiting. Concurrent process failures now exit with status 1. The stopContainer() assignment is reformatted without behavior changes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: charlesmulder

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is too brief and omits the required issue link, testing details, checklist, and reviewer information. Add a 2–3 sentence summary, the relevant issue link, testing results, checklist status, and any reviewer notes; remove the screenshots section if not applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: proper cleanup of the dev-proxy process after CTRL+C interruption.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/config/src/bin/dev-proxy-script.ts`:
- Around line 368-377: Move the SIGINT and SIGTERM handlers to immediately after
the cleanup function is defined, before concurrently() or exec() starts any
child processes. Preserve both handlers’ existing behavior of calling cleanup()
and exiting with status 0.
- Around line 368-377: Update cleanup() to accept a completion callback, invoke
treeKill(pid, 'SIGKILL', callback) for each process, and call the callback only
after all process-tree kills finish. Replace the separate SIGINT/SIGTERM
handlers with a shared one-shot shutdown handler that waits for cleanup to
complete before calling process.exit(0), preventing repeated cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c2add71-5ac0-4f13-bfc1-a94b12079428

📥 Commits

Reviewing files that changed from the base of the PR and between 7e09237 and b7615db.

📒 Files selected for processing (1)
  • packages/config/src/bin/dev-proxy-script.ts

Comment thread packages/config/src/bin/dev-proxy-script.ts Outdated
@charlesmulder

charlesmulder commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Hi @adonispuente Please update the commit message to fix(@redhat-cloud-services/frontend-components-config): clean up properly with CTRL+C.

Commit messages now need to include the full package names of affected packages.

@charlesmulder charlesmulder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please tend to CodeRabbit comments.

@adonispuente

Copy link
Copy Markdown
Contributor Author

@charlesmulder thank you for the quick look, I believe Ive addressed the code rabbit comments as well as fixed the commit message!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/config/src/bin/dev-proxy-script.ts (1)

259-299: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add explicit return types to the lifecycle helpers.

Annotate both cleanup and shutdown with : void.

Proposed fix
-  const cleanup = (onComplete?: () => void) => {
+  const cleanup = (onComplete?: () => void): void => {
...
-  const shutdown = (exitCode = 0) => {
+  const shutdown = (exitCode = 0): void => {

As per path instructions: packages/*/src/**/*.{ts,tsx} requires checking for missing return types on functions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/config/src/bin/dev-proxy-script.ts` around lines 259 - 299, Annotate
the lifecycle helper functions cleanup and shutdown with explicit : void return
types, preserving their existing control flow and callback behavior.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/config/src/bin/dev-proxy-script.ts`:
- Around line 291-299: Replace both direct process exits in the Chrome/container
startup catch and the outer catch around concurrently()/exec() with shutdown(1),
ensuring all failure paths use the centralized cleanup in shutdown. Preserve the
existing successful shutdown behavior and exit-code handling.

---

Nitpick comments:
In `@packages/config/src/bin/dev-proxy-script.ts`:
- Around line 259-299: Annotate the lifecycle helper functions cleanup and
shutdown with explicit : void return types, preserving their existing control
flow and callback behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c042574-81d2-4823-93a9-1df8fbb2824f

📥 Commits

Reviewing files that changed from the base of the PR and between b7615db and 16609ff.

📒 Files selected for processing (1)
  • packages/config/src/bin/dev-proxy-script.ts

Comment thread packages/config/src/bin/dev-proxy-script.ts Outdated
@charlesmulder

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@charlesmulder

charlesmulder commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@adonispuente I tested on local by checking out your branch to local. I can see the commit.

16609ff3 (HEAD -> cleanup, adonispuente/cleanup) fix(@redhat-cloud-services/frontend-components-config): clean up properly with CTRL+C

Then building and packaging the package with your commit.

# build
nvm use
npx nx run @redhat-cloud-services/frontend-components-config:build
# package
cd dist/@redhat-cloud-services/frontend-components-config
npm pack # redhat-cloud-services-frontend-components-config-6.14.1.tgz

Then ran it from frontend-starter-app

npm install --save ../frontend-components/dist/@redhat-cloud-services/frontend-components-config/redhat-cloud-services-frontend-components-config-6.14.1.tgz
npx fec dev-proxy

Once started I killed the process with ctrl+c and checked to see if relevant ports were still in use. All clear.

lsof -i :1337
lsof -i :8003
lsof -i :9998

Tried it again. Ran npx fec dev-proxy again and again ctrl+c, but this time port 1337 was still in use.

lsof -i :1337
COMMAND      PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
pasta.avx 570158 chmulder  152u  IPv6 7723274      0t0  TCP *:menandmice-dns (LISTEN)

charlesmulder
charlesmulder previously approved these changes Jul 29, 2026
@charlesmulder
charlesmulder dismissed their stale review July 29, 2026 11:57

Testing some more

@adonispuente

Copy link
Copy Markdown
Contributor Author

@charlesmulder there were 2 issues

  1. Line 66 — isRunning assignment bug: The result of the execSync check was never assigned back to isRunning, so
    stopContainer always assumed the container was running.
  2. Lines 267, 270 — Added removeContainer() to cleanup: Previously, Ctrl+C only called stopContainer() which tells
    Podman to stop, but doesn't tear down the network namespace. The pasta.avx process (Podman's rootless networking)
    would linger and hold port 1337. Adding removeContainer() after stopContainer() forces full teardown — matching what
    the startup code already does (line 246-252).

With the new changes, after testing iop mode and with your instructions I got the desire behavior repeatedly

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/config/src/bin/dev-proxy-script.ts`:
- Around line 400-401: Update the rejection callback passed to concurrently in
the dev proxy script so it calls shutdown with a nonzero failure exit code
instead of 0. Keep the success callback unchanged with shutdown(0), ensuring
BUILD/SERVE/PROXY failures propagate as unsuccessful exits.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: e25b71dd-679d-4f83-b3da-087b069f3edc

📥 Commits

Reviewing files that changed from the base of the PR and between 16609ff and 724dff9.

📒 Files selected for processing (1)
  • packages/config/src/bin/dev-proxy-script.ts

Comment thread packages/config/src/bin/dev-proxy-script.ts Outdated
@charlesmulder

charlesmulder commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@adonispuente

# ctrl+c
^C[fec] Info:  Closing frontend CRD watcher
[SERVE] http-server stopped.
[BUILD] [fec] Info:  Closing frontend CRD watcher
[BUILD] [fec] Info:  Closing frontend CRD watcher
[fec] Info:  Closing frontend CRD watcher
[fec] Error:  Chrome server stopped unexpectedly! The server port 9998 is already in use!

# waited and ran it multiple times
$ lsof -i :1337
COMMAND       PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
chrome    1160275 chmulder   63u  IPv4 14140054      0t0  TCP localhost:53562->localhost:menandmice-dns (ESTABLISHED)
pasta.avx 1198183 chmulder   88u  IPv6 14130960      0t0  TCP localhost:menandmice-dns->localhost:53562 (ESTABLISHED)
pasta.avx 1198183 chmulder  154u  IPv6 14159986      0t0  TCP *:menandmice-dns (LISTEN)

$ podman ps
CONTAINER ID  IMAGE                                                                                       COMMAND     CREATED         STATUS         PORTS                                                       NAMES
a13c92516d9f  quay.io/redhat-user-workloads/hcc-platex-services-tenant/frontend-development-proxy:latest              32 seconds ago  Up 32 seconds  0.0.0.0:1337->1337/tcp, 80/tcp, 443/tcp, 2019/tcp, 443/udp  frontend-development-proxy

Proof it's using the updated script

grep -rn removeContainer node_modules/@redhat-cloud-services/frontend-components-config/
node_modules/@redhat-cloud-services/frontend-components-config/bin/dev-proxy-script.js:128:function removeContainer(containerName) {
node_modules/@redhat-cloud-services/frontend-components-config/bin/dev-proxy-script.js:335:                    removeContainer(DEV_PROXY_CONTAINER_NAME);
node_modules/@redhat-cloud-services/frontend-components-config/bin/dev-proxy-script.js:343:                            removeContainer(DEV_PROXY_CONTAINER_NAME);
node_modules/@redhat-cloud-services/frontend-components-config/bin/dev-proxy-script.js:346:                                removeContainer(serve_chrome_1.CONTAINER_NAME);

@adonispuente

Copy link
Copy Markdown
Contributor Author

@charlesmulder im unsure why i cant reproduce this on my end, taking another wack at it now

@adonispuente

Copy link
Copy Markdown
Contributor Author

@charlesmulder Running it your way as well as in IOP mode, i was able to confirm the ports are always removed. Its a little overkill, and often times in the terminal you can see '''[fec] Error: Failed to remove the container: frontend-development-proxy''' , but thats because after the -rm, im also do removeContainer JUST INCASE rm doesnt work for whatever reason.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/config/src/bin/dev-proxy-script.ts`:
- Around line 25-43: Update killProcessTree to use a cross-platform process-tree
termination mechanism such as tree-kill, or equivalent platform-specific
cleanup, instead of invoking pgrep -P. Ensure cleanup terminates the target
process and all descendants on both Unix-like systems and Windows, while
preserving the existing tolerance for already-terminated processes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: c1820916-0628-4ef1-93b6-47ac960d3529

📥 Commits

Reviewing files that changed from the base of the PR and between 724dff9 and f435b99.

📒 Files selected for processing (2)
  • packages/config/src/bin/dev-proxy-script.ts
  • packages/config/src/bin/serve-chrome.ts

Comment thread packages/config/src/bin/dev-proxy-script.ts
@charlesmulder

Copy link
Copy Markdown
Contributor

@adonispuente Is the --rm arg a new addition, which negates the need for removeContainer function?

Comment thread packages/config/src/bin/serve-chrome.ts
@charlesmulder charlesmulder changed the title fix(cleanup): clean up properly with CTRL+C fix(@redhat-cloud-services/frontend-components-config): clean up properly with CTRL+C Aug 5, 2026
@adonispuente

Copy link
Copy Markdown
Contributor Author

@adonispuente Is the --rm arg a new addition, which negates the need for removeContainer function?

Its essentially overkill, --rm handles the normal case, but removeContainer is kept as a safety net for edge
cases (previous containers started without --rm, unclean shutdowns). It's a no-op when --rm works, so there's no downside to keeping
both.

I was only testing originally in IOP mode, but with the devproxy script or however else itd be ran, i figured it be better to be safe than sorry

@charlesmulder
charlesmulder merged commit 595fb35 into RedHatInsights:master Aug 5, 2026
14 of 15 checks passed
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.

2 participants