SeleniumHQ / SeleniumHQ/docker-selenium

[🐛 Bug]: terminationGracePeriodSeconds is hardcoded to 30 for scalingType job, ignoring both configured values

Open
#3,213 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
8.7k
Forks
2.5k
Avg merge
10h 16m
Merged PRs (30d)
20

Description

What happened?

With autoscaling.scalingType: job, a browser node pod always renders terminationGracePeriodSeconds: 30. Both configurable values are ignored.

seleniumGrid.node.terminationGracePeriodSeconds in templates/_helpers.tpl reads autoscaling.terminationGracePeriodSeconds and the per-node <node>.terminationGracePeriodSeconds, then discards both and returns a literal 30 when KEDA is enabled and scalingType is job:

{{- $autoscalingPeriod := default 0 .Values.autoscaling.terminationGracePeriodSeconds | int -}}
{{- $nodePeriod := default 0 .node.terminationGracePeriodSeconds | int -}}
{{- $period := $nodePeriod -}}
{{- if and (eq .Values.autoscaling.scalingType "deployment") (eq (include "seleniumGrid.useKEDA" $) "true") -}}
  {{- $period = ternary $nodePeriod $autoscalingPeriod (gt $nodePeriod $autoscalingPeriod) -}}
{{- else if and (eq .Values.autoscaling.scalingType "job") (eq (include "seleniumGrid.useKEDA" $) "true") }}
  {{- $period = 30 -}}
{{- end -}}

The chart README documents the per-node override with a worked chromeNode: terminationGracePeriodSeconds: 7200 example. That example sits under a heading scoped to deployment, but the README never states what job mode uses, and nothing warns that the override is inert there. So on a job-scaled grid the documented setting renders no change and gives no signal that it was ignored.

Why this matters in practice: in job mode the preStop hook drains the node and waits for the running session to finish. That is fine while pods complete on their own, which is the normal job lifecycle. But when a pod is deleted mid-session — a chart upgrade rolling the control plane, a node drain, or cluster-autoscaler consolidation — the hook is killed once the window expires and the session dies. With the window fixed at 30s there is no supported way to widen it, so any session longer than that is unprotected against pod deletion.

Two possible resolutions, and I would rather ask than assume:

  1. Honour the configured value in job mode (falling back to 30 when neither is set). This is the one that would actually help, since it makes the window tunable to real session lengths.
  2. If the fixed window is deliberate for job scaling, then documenting it — stating what job mode uses and that the override does not apply there — would at least remove the trap.

Happy to open a PR for either once you say which you would accept.

Command used to start Selenium Grid with Docker (or Kubernetes)
# 1. job mode + per-node override -> renders 30
helm template t ./charts/selenium-grid \
  --set autoscaling.enabled=true --set autoscaling.scalingType=job \
  --set chromeNode.terminationGracePeriodSeconds=7200 \
  | yq 'select(.kind=="ScaledJob" and (.metadata.name|test("chrome"))) | .spec.jobTargetRef.template.spec.terminationGracePeriodSeconds'

# 2. job mode + autoscaling-level value -> renders 30
helm template t ./charts/selenium-grid \
  --set autoscaling.enabled=true --set autoscaling.scalingType=job \
  --set autoscaling.terminationGracePeriodSeconds=7200 \
  | yq 'select(.kind=="ScaledJob" and (.metadata.name|test("chrome"))) | .spec.jobTargetRef.template.spec.terminationGracePeriodSeconds'

# 3. deployment mode + per-node override -> renders 7200 (works as documented)
helm template t ./charts/selenium-grid \
  --set autoscaling.enabled=true --set autoscaling.scalingType=deployment \
  --set chromeNode.terminationGracePeriodSeconds=7200 \
  | yq 'select(.kind=="Deployment" and (.metadata.name|test("chrome"))) | .spec.template.spec.terminationGracePeriodSeconds'
Relevant log output
# rendered terminationGracePeriodSeconds from the three commands above
1. job mode,        chromeNode.terminationGracePeriodSeconds=7200  -> 30
2. job mode,        autoscaling.terminationGracePeriodSeconds=7200 -> 30
3. deployment mode, chromeNode.terminationGracePeriodSeconds=7200  -> 7200

# what it looks like when a pod is deleted while a session is still running:
# the hook is still waiting for the slot to clear when the window expires
Warning  FailedPreStopHook  pod/<release>-selenium-node-chrome-xxxxx-yyyyy   PreStopHook failed
Operating System

Linux (GKE)

Docker Selenium version (image tag)

4.47.0-20260808

Selenium Grid chart version (chart version)

0.58.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in templates/_helpers.tpl at seleniumGrid.node.terminationGracePeriodSeconds, then read the chart README section describing the per-node override. Run the three helm template and yq commands from the issue to reproduce the job and deployment outputs. Done means the accepted behavior is implemented or the job-mode limitation is clearly documented, with the rendered result matching that decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
helm, kubernetes
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.