Skip to content

Conversation

@sinkingpoint
Copy link

@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

codecov bot commented Oct 21, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.26%. Comparing base (a646a2e) to head (6a5a94c).

Files with missing lines Patch % Lines
config/confighttp/server.go 55.55% 2 Missing and 2 partials ⚠️
config/confighttp/listen_config_other.go 83.33% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (71.42%) 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   92.27%   92.26%   -0.01%     
==========================================
  Files         656      657       +1     
  Lines       41050    41070      +20     
==========================================
+ Hits        37877    37892      +15     
- Misses       2172     2175       +3     
- Partials     1001     1003       +2     

☔ 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
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
@axw
Copy link
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
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
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
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


func TestServerReusePort(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test: SO_REUSEPORT is not supported on windows")
Copy link
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?

@sinkingpoint sinkingpoint force-pushed the sinkingpoint/so-reuse-port branch 2 times, most recently from 3d1484b to e063074 Compare October 22, 2025 13:49
@dmathieu
Copy link
Member

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

@sinkingpoint
Copy link
Author

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

@axw
Copy link
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
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
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

@sinkingpoint
Copy link
Author

Done. Is there anything blocking this PR then? I see the CodeCov, but those lines are covered, just in the windows tests (which tracks the error flow)

@axw axw added the ready-to-merge Code review completed; ready to merge by maintainers label Oct 24, 2025
@axw
Copy link
Contributor

axw commented Oct 24, 2025

@sinkingpoint nope, looks good to go. I've marked it ready to merge, just needs a look from a maintainer now.

@axw axw mentioned this pull request Oct 24, 2025
8 tasks
Comment on lines +12 to +18
func (sc *ServerConfig) getListenConfig() (net.ListenConfig, error) {
if sc.ReusePort {
return net.ListenConfig{}, errors.New("ReusePort is not supported on this platform")
}

return net.ListenConfig{}, nil
}
Copy link
Member

@bogdandrutu bogdandrutu Oct 27, 2025

Choose a reason for hiding this comment

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

I would also like to have this in Validate and fail during dry-run.

Copy link
Author

Choose a reason for hiding this comment

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

@bogdandrutu The ServerConfig doesn't have a Validate yet - are you proposing I add one?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, introducing Validate should be another PR.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, introducing Validate should be another PR.

why?

Copy link
Member

@bogdandrutu bogdandrutu Oct 28, 2025

Choose a reason for hiding this comment

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

The ServerConfig doesn't have a Validate yet - are you proposing I add one?

Yes please, every time we add fields that need to be validated we should validate them and if that needs a Validate func we add it.

Copy link
Author

Choose a reason for hiding this comment

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

Added @bogdandrutu

Copy link
Member

Choose a reason for hiding this comment

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

why?

Because that's a separate change that would need its own changelog entry, and having atomic PRs facilitates reviews.

@dmathieu dmathieu removed the ready-to-merge Code review completed; ready to merge by maintainers label Oct 28, 2025
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 <[email protected]>
Signed-off-by: sinkingpoint <[email protected]>
This adds a new Validate method that checks the getListenConfig call so
that the new SO_REUSEPORT stuff fails in dry run on Windows

Signed-off-by: sinkingpoint <[email protected]>
@sinkingpoint sinkingpoint force-pushed the sinkingpoint/so-reuse-port branch from 1073d97 to 6a5a94c Compare October 28, 2025 09:23
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.

4 participants