Skip to content

Fix flaky pkg/flare TestProcessAgentFullConfig (FLREM-152) - #54961

Draft
pducolin wants to merge 1 commit into
mainfrom
pducolin/flrem-152-testprocessagentfullconfig-fix
Draft

Fix flaky pkg/flare TestProcessAgentFullConfig (FLREM-152)#54961
pducolin wants to merge 1 commit into
mainfrom
pducolin/flrem-152-testprocessagentfullconfig-fix

Conversation

@pducolin

Copy link
Copy Markdown
Collaborator

What broke

pkg/flare.TestProcessAgentFullConfig failed on CI. The subtest was "verify_auth". This is tracked in FLREM-152.

Root cause

The test picks a free TCP port. It does this by opening a listener, reading its port, and closing it right away. Then it starts a real API server on that same port number.

There is a gap between closing the listener and starting the real server. In that gap, another process on the same machine can take the port. When that happens, the server fails to start with "address already in use".

This is more likely on CI hosts. CI runs many test binaries at the same time.

The same pattern also exists in TestProcessAgentChecks.

Fix

The helper setupProcessAPIServer now picks the port and starts the server together. If the start fails because the port is taken, it picks a new port and tries again, up to 5 times.

The two call sites no longer pick the port themselves. They just call the helper. This removes the duplicated, unsafe code.

Testing

Ran pkg/flare tests locally on macOS ARM64, the same platform as the failing CI job. All 47 tests pass, including TestProcessAgentFullConfig and TestProcessAgentChecks.

Ref: FLREM-152

The "verify auth" subtest picked a free port, closed the listener, then
started the process-agent API server on that same port number. Between
the close and the real bind, another process on the CI host could grab
the port first, failing the server with "address already in use". This
caused the flaky failures tracked in FLREM-152 on macOS ARM64 runners.

setupProcessAPIServer now retries with a fresh port when it hits this
bind error, and the port selection lives in that shared helper so both
call sites (TestProcessAgentFullConfig and TestProcessAgentChecks) get
the fix.
@github-actions

Copy link
Copy Markdown
Contributor

@codex review

@dd-octo-sts dd-octo-sts Bot added internal Identify a non-fork PR team/fleet-remediation labels Aug 17, 2026
@github-actions github-actions Bot added the short review PR is simple enough to be reviewed quickly label Aug 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84bb722167

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pkg/flare/archive_test.go
t.Cleanup(func() { _ = app.Stop(context.Background()) })
return
}
if attempt >= maxAttempts || !strings.Contains(startErr.Error(), "address already in use") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Detect address-in-use errors portably

When the port is stolen on Windows, net.Listen reports the platform-specific message “Only one usage of each socket address” (already asserted in test/new-e2e/tests/agent-subcommands/run_win_test.go:52), so this substring check is false and the helper fails on the first collision instead of retrying. This leaves both auth tests flaky in the Windows unit-test job; classify the wrapped error using a portable address-in-use check rather than matching the Unix/macOS text.

AGENTS.md reference: AGENTS.md:L177-L178

Useful? React with 👍 / 👎.

@datadog-datadog-prod-us1

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor bbbb55a
📊 Static Quality Gates Dashboard
🔗 SQG Job
SOME SIZE DELTAS ARE N/A (ANCESTOR METRICS NOT YET AVAILABLE). RETRY JOB

Successful checks

Info

Quality gate Change Size (prev → curr → max)
agent_deb_amd64 N/A N/A → 748.836 → 758.200
agent_deb_amd64_fips N/A N/A → 703.849 → 709.840
agent_heroku_amd64 N/A N/A → 307.935 → 315.230
agent_rpm_amd64 N/A N/A → 748.820 → 758.170
agent_rpm_amd64_fips N/A N/A → 703.832 → 709.840
agent_rpm_arm64 N/A N/A → 724.099 → 729.660
agent_rpm_arm64_fips N/A N/A → 682.859 → 688.860
agent_suse_amd64 N/A N/A → 748.820 → 758.170
agent_suse_amd64_fips N/A N/A → 703.832 → 709.840
agent_suse_arm64 N/A N/A → 724.099 → 729.660
agent_suse_arm64_fips N/A N/A → 682.859 → 688.860
docker_agent_amd64 N/A N/A → 807.632 → 813.790
docker_agent_arm64 N/A N/A → 807.963 → 815.030
docker_agent_jmx_amd64 N/A N/A → 998.530 → 1004.550
docker_agent_jmx_arm64 N/A N/A → 987.513 → 994.710
docker_cluster_agent_amd64 N/A N/A → 209.315 → 210.470
docker_cluster_agent_arm64 N/A N/A → 222.386 → 222.980
docker_cws_instrumentation_amd64 N/A N/A → 7.447 → 7.480
docker_cws_instrumentation_arm64 N/A N/A → 6.877 → 7.110
docker_dogstatsd_amd64 N/A N/A → 39.145 → 39.910
docker_dogstatsd_arm64 N/A N/A → 37.242 → 38.270
docker_host_profiler_amd64 N/A N/A → 302.494 → 317.640
docker_host_profiler_arm64 N/A N/A → 314.048 → 328.900
dogstatsd_deb_amd64 N/A N/A → 29.880 → 31.150
dogstatsd_deb_arm64 N/A N/A → 27.920 → 29.530
dogstatsd_rpm_amd64 N/A N/A → 29.880 → 31.150
dogstatsd_suse_amd64 N/A N/A → 29.880 → 31.150
iot_agent_deb_amd64 N/A N/A → 45.825 → 46.380
iot_agent_deb_arm64 N/A N/A → 42.528 → 43.720
iot_agent_deb_armhf N/A N/A → 43.309 → 43.960
iot_agent_rpm_amd64 N/A N/A → 45.826 → 46.380
iot_agent_suse_amd64 N/A N/A → 45.825 → 46.380

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

Labels

internal Identify a non-fork PR short review PR is simple enough to be reviewed quickly team/fleet-remediation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant