Skip to content

Allow binding multiple addresses#79

Open
gjcairo wants to merge 7 commits into
mainfrom
multiple-addresses
Open

Allow binding multiple addresses#79
gjcairo wants to merge 7 commits into
mainfrom
multiple-addresses

Conversation

@gjcairo
Copy link
Copy Markdown
Collaborator

@gjcairo gjcairo commented May 13, 2026

This PR adds support for binding a NIOHTTPServer to multiple addresses simultaneously.

The configuration API now also accepts an array of BindTargets. All resulting channels are served concurrently using the same request handler.

The server treats its listening addresses as a unit: if any channel stops serving for any reason, all remaining channels are are also cancelled. This behaviour matches the current behaviour with a single listening address.

The listeningAddress property has been replaced by listeningAddresses, an array of addresses.

@gjcairo gjcairo added the 🆕 semver/minor Adds new public API. label May 13, 2026
@gjcairo gjcairo requested a review from FranzBusch May 13, 2026 15:25
Copy link
Copy Markdown
Collaborator

@ehaydenr ehaydenr left a comment

Choose a reason for hiding this comment

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

Lgtm!

Comment thread Sources/NIOHTTPServer/NIOHTTPServer+HTTP1_1.swift Outdated
Comment thread Sources/NIOHTTPServer/NIOHTTPServer+ListeningAddress.swift Outdated
handler: some HTTPServerRequestHandler<RequestConcludingReader, ResponseConcludingWriter>
) async throws {
let serverChannel = try await self.makeServerChannel()
let serverChannels = try await self.makeServerChannels()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We bind each channel to the listening addresses in this method. Does this method throw if the bind failed for a particular channel?

I'm wondering if we can reach a state where some channels are bound to an address and some are not; we should make sure that the channels which have already started are then closed in this case.

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.

Yeah good catch, we should close the channels. I'd assumed dropping the channels would trigger closes but I forgot we deprecated the closeOnDeinit by default on NIOAsyncChannel. I've fixed this.

Comment thread Tests/NIOHTTPServerTests/NIOHTTPServerTests.swift Outdated
public var backpressureStrategy: BackPressureStrategy

/// Create a new configuration.
/// Create a new configuration with multiple bind targets.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We'll need to update the swift-configuration initializer (and the markdown reference table) too now that multiple bind targets are supported.

@gjcairo gjcairo force-pushed the multiple-addresses branch from 76df44e to 4b38661 Compare May 14, 2026 13:30
@gjcairo gjcairo requested a review from aryan-25 May 14, 2026 13:30
@gjcairo gjcairo force-pushed the multiple-addresses branch from 7db71c8 to 1726688 Compare May 15, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants