Skip to content

Add ReusePort config to confighttp#14058

Open
sinkingpoint wants to merge 26 commits intoopen-telemetry:mainfrom
sinkingpoint:sinkingpoint/so-reuse-port
Open

Add ReusePort config to confighttp#14058
sinkingpoint wants to merge 26 commits intoopen-telemetry:mainfrom
sinkingpoint:sinkingpoint/so-reuse-port

Conversation

@sinkingpoint
Copy link
Copy Markdown

@sinkingpoint sinkingpoint commented Oct 21, 2025

Description

This adds in a new field, ReusePort that, if set, sets the SO_REUSEPORT socket option on the listener port. If we're on non unix, this errors out instead as AFAIK SO_REUSEPORT isn't available. Cursory googling says that SO_REUSEADDR might work, but I don't have a windows machine to test on.

Link to tracking issue

#14046

Testing

We add a new test, TestServerReusePort which checks the behaviour of both setting and unsetting the ReusePort config with the expectation of an error if it isn't set and it not erroring when binding twice to the same port

@sinkingpoint sinkingpoint requested a review from a team as a code owner October 21, 2025 09:23
@sinkingpoint sinkingpoint requested a review from dmitryax October 21, 2025 09:23
@sinkingpoint sinkingpoint force-pushed the sinkingpoint/so-reuse-port branch 5 times, most recently from 636ae93 to 344b948 Compare October 21, 2025 09:39
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 21, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.29%. Comparing base (22a5e61) to head (c90e0fb).

Files with missing lines Patch % Lines
config/confignet/confignet.go 33.33% 2 Missing and 2 partials ⚠️
config/confignet/listen_config_unix.go 83.33% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14058      +/-   ##
==========================================
- Coverage   91.31%   91.29%   -0.03%     
==========================================
  Files         699      700       +1     
  Lines       44939    44956      +17     
==========================================
+ Hits        41036    41041       +5     
- Misses       2759     2766       +7     
- Partials     1144     1149       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sinkingpoint
Copy link
Copy Markdown
Author

Contrib test failure fixed here: open-telemetry/opentelemetry-collector-contrib#43681

sinkingpoint added a commit to sinkingpoint/opentelemetry-collector-contrib that referenced this pull request Oct 21, 2025
Without a valid `runCtx`, anything that attempts to use the context
segfaults. In
open-telemetry/opentelemetry-collector#14058 I
am using the context, so this test borks. This adds the runCtx to fix
it.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
sinkingpoint added a commit to sinkingpoint/opentelemetry-collector-contrib that referenced this pull request Oct 21, 2025
Without a valid `runCtx`, anything that attempts to use the context
segfaults. In
open-telemetry/opentelemetry-collector#14058 I
am using the context, so this test borks. This adds the runCtx to fix
it.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
songy23 pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Oct 21, 2025
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Without a valid `runCtx`, anything that attempts to use the context
segfaults. In
open-telemetry/opentelemetry-collector#14058 I
am using the context, so this test borks. This adds the runCtx to fix
it.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
open-telemetry/opentelemetry-collector#14058

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@axw
Copy link
Copy Markdown
Contributor

axw commented Oct 22, 2025

Should we have this for configgrpc too? And non-HTTP/gRPC?

I'm wondering if we should make a breaking change to confighttp.ServerConfig to use confignet.AddrConfig, similar to configgrpc:

NetAddr confignet.AddrConfig `mapstructure:",squash"`

Then we could add ReusePort to confignet.AddrConfig and have it in one place.

(Not necessarily all in this PR, just thinking out loud about how to generalise this change.)

@sinkingpoint
Copy link
Copy Markdown
Author

Should we have this for configgrpc too? And non-HTTP/gRPC?

I was going to do those in a separate PR, but rely on "A little copying is better than a little dependency" and just copy the same config changes across. Breaking changes scare me

@axw
Copy link
Copy Markdown
Contributor

axw commented Oct 22, 2025

@sinkingpoint 👍 that seems fine, we can always make a breaking change independently if desired.

@sinkingpoint sinkingpoint force-pushed the sinkingpoint/so-reuse-port branch from bac556b to 8f6079d Compare October 22, 2025 12:55
@sinkingpoint
Copy link
Copy Markdown
Author

sinkingpoint commented Oct 22, 2025

Actually, looking at it a bit more: configgrpc provides .Serve(net.Listener), and all the uses in the contrib repo actually use confighttps ToListener to create the listener to pass into that, so this handles both

Comment thread config/confighttp/server_test.go Outdated

func TestServerReusePort(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test: SO_REUSEPORT is not supported on windows")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a test checking that we do get an error when trying to use SoReuse on windows?

Comment thread .chloggen/so-reuse-port.yaml Outdated
@sinkingpoint sinkingpoint force-pushed the sinkingpoint/so-reuse-port branch from 8f6079d to 3d1484b Compare October 22, 2025 13:49
This adds in a new field, `ReusePort` that, if set, sets the
SO_REUSEPORT socket option on the listener port. If we're on non unix,
this errors out instead as AFAIK SO_REUSEPORT isn't available. Cursory
testing says that SO_REUSEADDR _might_ work, but I don't have a windows
machine to test on.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint sinkingpoint force-pushed the sinkingpoint/so-reuse-port branch from 3d1484b to e063074 Compare October 22, 2025 13:49
@dmathieu
Copy link
Copy Markdown
Member

Could you avoid force-pushing? That breaks the GitHub review interface.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint
Copy link
Copy Markdown
Author

Apologies 😬 I think I've fixed it up now anyway

@axw
Copy link
Copy Markdown
Contributor

axw commented Oct 23, 2025

Actually, looking at it a bit more: configgrpc provides .Serve(net.Listener), and all the uses in the contrib repo actually use confighttps ToListener to create the listener to pass into that, so this handles both

Where did you see that being done? I found the stef receiver is not using confighttp, for example: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/e3f1205a034ff05c1c31e1e1b84a8bf735563d91/receiver/stefreceiver/stef.go#L57-L77

@sinkingpoint
Copy link
Copy Markdown
Author

Oh hrm.. I checked several, like https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/skywalkingreceiver/skywalking_receiver.go#L144 , but you're right - missed the ones that use confignet. Want me to update that here? Or put in a seperate PR?

@axw
Copy link
Copy Markdown
Contributor

axw commented Oct 23, 2025

Ah I see. That receiver probably should be updated, but I digress

A separate PR sounds good to me, maybe change the description so the issue doesn't get closed when this PR is merged

@axw
Copy link
Copy Markdown
Contributor

axw commented Jan 6, 2026

Done @axw . Do you have an ETA on #14248 ? confighttp was the one I really cared about in the first place

Thank you 🙏

I don't have an ETA, just waiting on a maintainer to merge it - I imagine many of whom are coming back from time off.

Comment thread config/confignet/listen_config_other.go Outdated
As per PR comments, this moves things around so that listen_config_other
becomes listen_config_unix, and listen_config_windows becomes
listen_config_other, with appropriate build gating.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint
Copy link
Copy Markdown
Author

@bogdandrutu @dmitryax Does this look OK now?

@evan-bradley evan-bradley removed the ready-to-merge Code review completed; ready to merge by maintainers label Jan 26, 2026
Copy link
Copy Markdown
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Thanks for your patience with the long review cycle @sinkingpoint.

Comment thread config/confignet/confignet_test.go Outdated
Comment thread config/confignet/listen_config_unix.go
Comment thread config/confignet/confignet.go Outdated
Comment thread config/confignet/confignet.go
@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Feb 13, 2026
Signed-off-by: sinkingpoint <colin@quirl.co.nz>
Signed-off-by: sinkingpoint <colin@quirl.co.nz>
This changes the if runtime.GOOS == "windows" { to properly match the
updated build tags

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint
Copy link
Copy Markdown
Author

@evan-bradley Can I get another look from you when you get a sec?

Copy link
Copy Markdown
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Thanks @sinkingpoint. I'd like to get approvals from a few other approvers/maintainers since this is a stable module and we can't revert this change once it's released.

Comment thread config/confignet/README.md Outdated
Comment thread config/confignet/confignet_test.go Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added Stale and removed Stale labels Mar 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Mar 22, 2026
@axw
Copy link
Copy Markdown
Contributor

axw commented Apr 2, 2026

@sinkingpoint I hope you don't mind, I took the liberty of addressing @evan-bradley's comments and pushing to your branch

@axw axw removed the Stale label Apr 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Apr 19, 2026
@axw axw removed the Stale label Apr 20, 2026
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.

6 participants