Skip to content

fix: prevent pkill -f self-kill in Makefile targets#5

Merged
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom
gomessguii:fix/makefile-pkill-self-kill
Apr 13, 2026
Merged

fix: prevent pkill -f self-kill in Makefile targets#5
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom
gomessguii:fix/makefile-pkill-self-kill

Conversation

@gomessguii
Copy link
Copy Markdown
Member

@gomessguii gomessguii commented Apr 13, 2026

On Linux (procps-ng) with dash as /bin/sh, pkill -f "pattern" inside a make recipe matches the recipe shell's own argv (since make runs each line as sh -c '<line>', putting the pattern literally in the shell's cmdline). pkill then SIGTERMs its own parent shell, causing Terminated and aborting the recipe before it does anything else.

Apply the classic [p]attern bracket trick so the regex still matches real target processes (dashboard/..., app.py) but the literal [d]ashboard/[a]pp.py string in the shell's own argv does not contain the substring being searched — pkill no longer matches itself.

Affects 5 targets: dashboard-app, terminal-stop, stop, uninstall, restore.

Reproduces reliably on WSL2 Ubuntu + dash + procps-ng 4.0.4. macOS users likely unaffected because BSD pkill / bash-as-sh handle sh -c argv differently, which is why this wasn't caught earlier.

Summary by Sourcery

Bug Fixes:

  • Update pkill patterns in Makefile service management targets to avoid self-matching and premature recipe termination on Linux shells.

On Linux (procps-ng) with dash as /bin/sh, `pkill -f "pattern"` inside
a make recipe matches the recipe shell's own argv (since make runs each
line as `sh -c '<line>'`, putting the pattern literally in the shell's
cmdline). pkill then SIGTERMs its own parent shell, causing `Terminated`
and aborting the recipe before it does anything else.

Apply the classic `[p]attern` bracket trick so the regex still matches
real target processes (`dashboard/...`, `app.py`) but the literal
`[d]ashboard`/`[a]pp.py` string in the shell's own argv does not contain
the substring being searched — pkill no longer matches itself.

Affects 5 targets: dashboard-app, terminal-stop, stop, uninstall, restore.

Reproduces reliably on WSL2 Ubuntu + dash + procps-ng 4.0.4. macOS users
likely unaffected because BSD pkill / bash-as-sh handle `sh -c` argv
differently, which is why this wasn't caught earlier.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Makefile pkill invocations to avoid killing their own recipe shell by using the classic bracketed-pattern trick in process-matching regexes, ensuring service stop/cleanup targets work reliably on Linux/dash without self-termination.

Sequence diagram for Makefile pkill behavior in dashboard-app target

sequenceDiagram
    actor Developer
    participant Make
    participant Shell
    participant Pkill
    participant TerminalServer

    Developer->>Make: make dashboard-app
    Make->>Shell: sh -c cd dashboard/frontend && ... && pkill -f [d]ashboard/terminal-server/bin/server.js
    Shell->>Pkill: pkill -f [d]ashboard/terminal-server/bin/server.js

    alt Matching terminal-server
        Pkill-->>Shell: return success (matched TerminalServer)
        Pkill-->>TerminalServer: SIGTERM
    else No matching terminal-server
        Pkill-->>Shell: return failure (no matches)
    end

    Note over Shell,Pkill: [d]ashboard pattern ensures Shell argv does not match itself

    Shell->>TerminalServer: node dashboard/terminal-server/bin/server.js --dev &
    Shell-->>Make: start backend via app.py
    Make-->>Developer: dashboard-app running
Loading

Flow diagram for Makefile service stop and cleanup targets using bracketed pkill patterns

flowchart TD
    subgraph MakeTargets
        A[dashboard-app] -->|cleanup existing| B["pkill -f [d]ashboard/terminal-server/bin/server.js"]
        C[terminal-stop] --> B
        D[stop] --> B
        D --> E["pkill -f [d]ashboard/backend.*app.py"]
        D --> F["pkill -f [a]pp.py"]
        G[uninstall] --> B
        G --> E
        G --> F
        H[restore] --> B
        H --> F
    end

    B --> I[Terminate terminal-server processes]
    E --> J[Terminate dashboard backend app.py processes]
    F --> K[Terminate generic app.py processes]

    classDef target fill:#e0f7ff,stroke:#0077aa,stroke-width:1px;
    classDef action fill:#fef3c7,stroke:#92400e,stroke-width:1px;

    class A,C,D,G,H target;
    class B,E,F,I,J,K action;
Loading

File-Level Changes

Change Details Files
Harden pkill patterns in Makefile recipes to avoid matching the shell’s own command line while still targeting the intended dashboard and app processes.
  • Wrap the leading character of dashboard-related pkill -f patterns in brackets to transform them into non-self-matching regexes in the dashboard-app and terminal-stop targets
  • Apply the same bracketed-leading-character pattern to pkill invocations for dashboard backend app.py and generic app.py in the stop target so they no longer match the invoking shell
  • Mirror these pkill pattern updates inside the uninstall target’s multi-line shell stanza to ensure its cleanup logic behaves consistently on Linux
  • Update the restore target’s pkill commands to use the bracket-trick patterns for terminal-server and app.py processes before running restore logic
Makefile

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="Makefile" line_range="133" />
<code_context>
-		pkill -f "app.py" 2>/dev/null || true; \
+		pkill -f "[d]ashboard/terminal-server/bin/server.js" 2>/dev/null || true; \
+		pkill -f "[d]ashboard/backend.*app.py" 2>/dev/null || true; \
+		pkill -f "[a]pp.py" 2>/dev/null || true; \
 		echo "Removing nginx config..."; \
 		rm -f /etc/nginx/sites-enabled/evonexus 2>/dev/null || true; \
</code_context>
<issue_to_address>
**issue (bug_risk):** Consider whether the broad `[a]pp.py` pattern might hit unrelated `app.py` processes on the host

`pkill -f "[a]pp.py"` will match any process whose command line contains `app.py`, not just this backend. On shared/dev hosts this could kill unrelated apps. Prefer a more specific pattern (e.g., including the project path, venv name, or a unique CLI argument).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread Makefile
pkill -f "app.py" 2>/dev/null || true; \
pkill -f "[d]ashboard/terminal-server/bin/server.js" 2>/dev/null || true; \
pkill -f "[d]ashboard/backend.*app.py" 2>/dev/null || true; \
pkill -f "[a]pp.py" 2>/dev/null || true; \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Consider whether the broad [a]pp.py pattern might hit unrelated app.py processes on the host

pkill -f "[a]pp.py" will match any process whose command line contains app.py, not just this backend. On shared/dev hosts this could kill unrelated apps. Prefer a more specific pattern (e.g., including the project path, venv name, or a unique CLI argument).

@DavidsonGomes DavidsonGomes merged commit 928b121 into EvolutionAPI:develop Apr 13, 2026
1 check 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