Skip to content

Fix preStop behavior for KEDA scale-down#2625

Open
kool79 wants to merge 2 commits intoSeleniumHQ:trunkfrom
kool79:patch-1
Open

Fix preStop behavior for KEDA scale-down#2625
kool79 wants to merge 2 commits intoSeleniumHQ:trunkfrom
kool79:patch-1

Conversation

@kool79
Copy link
Copy Markdown

@kool79 kool79 commented Apr 21, 2026

Description

Updated the preStop hook in example to decouple it from Selenium node command-line arguments. This prevents random node terminations during KEDA scale-down when use the standard docker images for nodes.
Removed "s" from the 'sleep' command to ensure compatibility with POSIX

Motivation and Context

The previous implementation of the preStop hook relied on Selenium node command-line arguments to delay shutdown until session finished. This made the logic fragile and dependent on how the node process was started, which could vary between environments or deployments.
In practice, this approach failed for the standard Docker Chrome node container, where the expected command-line structure is different.
As a result, during KEDA scale-down events, nodes were sometimes terminated unexpectedly before properly handling ongoing sessions.

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

Updated the preStop hook to decouple it from Selenium node command-line arguments. This prevents random node terminations during KEDA scale-down.
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 21, 2026

👷 Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 9f90be0

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix preStop hook for reliable KEDA scale-down behavior

🐞 Bug fix 📝 Documentation

Grey Divider

Walkthroughs

Description
• Replace fragile preStop hook relying on node command-line arguments
• Use health check polling instead of process-specific tail command
• Ensure compatibility with standard Docker Selenium node images
• Fix POSIX compliance by removing "s" from sleep command
Diagram
flowchart LR
  A["Old preStop Hook<br/>tail + sleep 30s"] -->|"Fragile, node-specific"| B["Failed on standard<br/>Docker images"]
  C["New preStop Hook<br/>Health check polling"] -->|"Robust, image-agnostic"| D["Works with all<br/>node configurations"]
Loading

Grey Divider

File Changes

1. website_and_docs/content/blog/2022/scaling-grid-with-keda.md 🐞 Bug fix +2/-2

Update preStop hook to use health check polling

• Replaced preStop hook command from process-specific tail approach to health check polling
• Changed from `tail --pid=$(pgrep -f '[n]ode --bind-host false --config /opt/selenium/config.toml')
 -f /dev/null; sleep 30s to while curl -fs localhost:5555/status >/dev/null; do sleep 1; done;
 sleep 10`
• Improved POSIX compliance by removing "s" suffix from sleep command
• Fixed newline at end of file

website_and_docs/content/blog/2022/scaling-grid-with-keda.md


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented Apr 21, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Inconsistent preStop instructions🐞 Bug ≡ Correctness
Description
The blog updates the first preStop command to poll /status and sleep 10, but the subsequent
breakdown text and the later “From Start to Finish” YAML snippet still describe the old
pgrep/tail + sleep 30s approach. Readers can easily copy the later/outdated instructions and
reintroduce the fragile CLI-dependent logic and non-POSIX sleep suffix this PR is trying to
eliminate.
Code

website_and_docs/content/blog/2022/scaling-grid-with-keda.md[121]

+              command: ["/bin/sh", "-c", "curl --request POST 'localhost:5555/se/grid/node/drain' --header 'X-REGISTRATION-SECRET;'; while curl -fs localhost:5555/status >/dev/null; do sleep 1; done; sleep 10"]
Evidence
The first YAML example was changed to a /status polling loop (line 121), but the immediately
following bullets still claim the hook tails the node process and then sleeps 30 seconds (lines
135–136). The later end-to-end YAML example still shows the old pgrep/tail logic and sleep 30s
(line 219), contradicting the updated recommendation in the same article.

website_and_docs/content/blog/2022/scaling-grid-with-keda.md[119-137]
website_and_docs/content/blog/2022/scaling-grid-with-keda.md[200-220]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The blog post is internally inconsistent: the first preStop YAML snippet was updated, but the “Breaking this down” section and the later “From Start to Finish” YAML snippet still describe/show the old `pgrep`/`tail` + `sleep 30s` behavior.

### Issue Context
This PR’s stated goal is to decouple shutdown behavior from Selenium node command-line arguments and improve POSIX compatibility (remove `sleep 30s`). Leaving the old explanation/snippet in place undermines that goal and can cause readers to deploy the wrong (fragile) hook.

### Fix Focus Areas
- website_and_docs/content/blog/2022/scaling-grid-with-keda.md[124-136]
- website_and_docs/content/blog/2022/scaling-grid-with-keda.md[208-220]

### What to change
- Update the bullet list under “Breaking this down” to describe the new `/status` polling loop and the final `sleep 10` (or adjust the command to match the narrative—pick one and make it consistent).
- Update the later “From Start to Finish” YAML snippet to use the same new preStop command (and remove `sleep 30s` / `pgrep`/`tail` references).
- Ensure any referenced wait duration (10 vs 30 seconds) matches the actual command shown.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread website_and_docs/content/blog/2022/scaling-grid-with-keda.md
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