Skip to content

Conversation

@rafaelcepeda
Copy link
Contributor

Added extra documentation to channel.remoteAddress field to capture a scenario where this field might be nil

Motivation:

It is somewhat common for users to have code like channel.remoteAddress! in their implementation, as it is a reasonable assumption to think a socket connection will have an associated remote address. However, in at least one known situation this might not be the case. When that happens, user's code might crash due to the force unwrap of the optional field.

Modifications:

Introduced more documentation to make it clear that users should be prepared to handle the nil scenario.

Result:

Less frequent mishandling of channel.remoteAddress.

@rafaelcepeda rafaelcepeda added the semver/none No version bump required. label Nov 28, 2025
///
/// If we end up accepting an already-closed connection, the kernel can end up in a place
/// where it has no remote address to give us. In this situation, `remoteAddress` will be
/// `nil`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The remote address can also be nil in cases where it isn't representable in SocketAddress, e.g. if we're talking over a vsock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Just updated the comment.

@Lukasa Lukasa enabled auto-merge (squash) December 1, 2025 10:56
@Lukasa Lukasa merged commit b60d141 into apple:main Dec 1, 2025
55 of 56 checks passed
@rafaelcepeda rafaelcepeda deleted the document_channel_remoteAddress branch December 1, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants