Skip to content

[ci] poll Elasticsearch until it comes up - #273

Open
jameslamb wants to merge 8 commits into
uptake:mainfrom
jameslamb:fix/ci
Open

jameslamb wants to merge 8 commits into
uptake:mainfrom
jameslamb:fix/ci

Conversation

@jameslamb

@jameslamb jameslamb commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #265

After seeing just that 8.0.1 job fail AGAIN on #272 I thought "ok, enough, let's just fix this".

See the inline comments for the investigation that led to these changes.

In short:

  • fixes the Elasticsearch 8.0.1 setup (it suffered from a Java bug related to container support)
  • adds docker ps / docker logs to setup_local.sh so we get more information when failures like this happen in the future
  • updates setup_local.sh to poll the Elasticsearch container until it's ready, which should allow us to tune timeouts to make this pass (and avoid a long sleep for other versions that don't need it!).
  • updates all pre-commit hooks with pre-commit autoupdate and fixes one finding from the latest version of zizmor

@jameslamb jameslamb added the maintenance miscellaneous maintenance label Sep 2, 2026
Comment thread setup_local.sh Outdated
;;
8.0.1)
docker run --rm -d -p "${ES_PORT}:9200" \
docker run --rm -d --name uptasticsearch -p "${ES_PORT}:9200" \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

wtf is going onnnnnnnnn

Elasticsearch did not become reachable within 1 minute
--- docker logs ---
Error response from daemon: No such container: uptasticsearch

(build link)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok so using docker run --rm meant the container wasn't there any more after it failed to come up, so docker logs couldn't show the logs.

Removing that, I was finally able to get some logs:

2026-09-02 02:10:35,533 main ERROR Could not reconfigure JMX java.lang.NullPointerException: Cannot invoke "jdk.internal.platform.CgroupInfo.getMountPoint()" because "anyController" is null
	at java.base/jdk.internal.platform.cgroupv2.CgroupV2Subsystem.getInstance(CgroupV2Subsystem.java:81)
	at java.base/jdk.internal.platform.CgroupSubsystemFactory.create(CgroupSubsystemFactory.java:113)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "jdk.internal.platform.CgroupInfo.getMountPoint()" because "anyController" is null

(build link)

It looks like this was actually a bug in Java, related to Linux cgroups v2 and how java processes detect the amount of available memory when running in a container: https://bugs.openjdk.org/browse/JDK-8287073

There's a note buried at the bottom of https://www.elastic.co/support/matrix about this 🙃

Elasticsearch versions 8.0.0–8.4.3 and 7.15.1–7.17.6 fail to start on hosts using cgroup v2 with the bundled JDK.

We're just running a lil baby test instance here and don't need to care about getting fancy with container support, so after all that the fix is to pass -e "JDK_JAVA_OPTIONS=-XX:-UseContainerSupport" to tell the JDK not to try to do any smart container-y stuff.

What a ride!

Comment thread setup_local.sh
sleep 30
# wait for the cluster to be reachable
echo "waiting for Elasticsearch to come up..."
SECONDS=0

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Learned about this while working on this tonight. I'd wanted to use timeout but that's one of those GNU things that isn't available by default on macOS.

From https://man7.org/linux/man-pages/man1/bash.1.html

Each time this parameter is referenced, it expands to the number of seconds since shell invocation. If a value is assigned to SECONDS, the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. The number of seconds at shell invocation and the current time are always determined by querying the system clock at one-second resolution. If SECONDS is unset, it loses its special properties, even if it is subsequently reset.

Comment thread setup_local.sh
;;
8.15.5)
docker run --rm -d -p "${ES_PORT}:9200" \
docker run -d --name uptasticsearch -p "${ES_PORT}:9200" \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removing --rm allows docker logs use later if the container doesn't come up.

Giving it a stable name with --name uptasticsearch makes the docker logs command easier.

Comment thread cleanup_local.sh
echo "killing running container"
docker kill "$(docker ps -ql)"
docker kill -f uptasticsearch
docker rm -f uptasticsearch

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The rm is needed because I dropped all the --rm from the docker run calls.

@jameslamb jameslamb changed the title WIP: [ci] poll Elasticsearch until it comes up [ci] poll Elasticsearch until it comes up Sep 2, 2026
@jameslamb
jameslamb marked this pull request as ready for review September 2, 2026 03:00
@jameslamb

Copy link
Copy Markdown
Collaborator Author

Hey Austin check it out 😊

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance miscellaneous maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use readiness poll when setting up container in CI

1 participant