Skip to content

Document SelectError results for out-of-band data on Linux and Apple platforms - #13301

Open
caraioniurie47 wants to merge 1 commit into
dotnet:mainfrom
caraioniurie47:selecterror-oob-docs
Open

caraioniurie47 wants to merge 1 commit into
dotnet:mainfrom
caraioniurie47:selecterror-oob-docs

Conversation

@caraioniurie47

@caraioniurie47 caraioniurie47 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Linux and on macOS, iOS, tvOS and Mac Catalyst, Socket.Poll(..., SelectMode.SelectError) doesn't follow its docs for out-of-band data. The docs say SelectError returns true "if OutOfBandInline is not set and out-of-band data is available", which is what Windows does, and the Select docs don't mention out-of-band data. Reviewing a fix for Apple platforms, dotnet/runtime#135996, an area owner suggested: "I would probably document it as platform limitation."

Linux

With OutOfBandInline set and an out-of-band byte not read yet, Poll(SelectError) returns true and Socket.Select keeps the socket in checkError. A loopback TCP pair, OutOfBandInline set on the receiver, one byte sent with SocketFlags.OutOfBand:

Linux Windows
Poll(0, SelectError) True False
Select checkError count 1 0

Linux follows POSIX, whose pselect page says: "A socket shall also be considered to have an exceptional condition pending if an out-of-band data mark is present in the receive queue." tcp_poll sets EPOLLPRI whatever SO_OOBINLINE says:

tcp.c:623-624

		if (urg_data & TCP_URG_VALID)
			mask |= EPOLLPRI;

Apple platforms

Poll(SelectError) doesn't report out-of-band data: it waits out the timeout and returns false. XNU's socket filter never returns EV_OOBAND, so poll() sets POLLPRI only along with POLLHUP:

sys_generic.c:1867-1875

	case EVFILT_READ:
		if (fds->revents & POLLHUP) {
			mask = (POLLIN | POLLRDNORM | POLLPRI | POLLRDBAND);
		} else {
			mask = (POLLIN | POLLRDNORM);
			if (kevp->flags & EV_OOBAND) {
				mask |= (POLLPRI | POLLRDBAND);
			}
		}

dotnet/runtime#135995 has the rest of the XNU analysis and the upstream CI failures on macOS 15 x64 and macOS 26 arm64 that showed it.

The change

Both Poll overloads' SelectError item gains a sentence for Linux and one for Apple platforms. The remarks of Select(IList, IList, IList, int) gain two sentences on out-of-band data after the one on failed connects. The Linux sentences say "on some platforms, such as Linux" because Linux is the only Unix platform where it ran.

Options not taken:

  • Apple platforms, select() for Poll(SelectError): Report out-of-band data from Socket.Poll(SelectError) on Apple platforms runtime#135996, declined above.
  • Apple platforms, kqueue with NOTE_OOB: a new native export and a kqueue descriptor per call.
  • Linux, leaving sockets with SO_OOBINLINE set out of the result: against POSIX, and code may use the report to learn that urgent data is pending.
  • Linux, the same for Poll only: the same costs, and Poll and Select would then disagree.

Fixes dotnet/runtime#135995

Note

AI-generated, written at my direction and reviewed by me before posting.
The Linux result ran on Ubuntu 24.04.5 LTS (kernel 6.18.44, x64) with .NET 8.0.32 and 11.0.0-rc.1.26420.103, the Windows one on Windows 11 with .NET 8.0.32 and 10.0.13. Nothing was run on Apple platforms: upstream CI on macOS ran the OutOfBandInline-off case (dotnet/runtime#135995); the rest is from the XNU xnu-12377.1.9 source.


Internal previews

File Preview link
xml/System.Net.Sockets/Socket.xml Learn preview

Build report

On Linux, Socket.Poll(SelectError) returns true, and Socket.Select
keeps the socket in checkError, when the socket has OutOfBandInline
set and out-of-band data hasn't been read yet, as POSIX defines. On
macOS, iOS, tvOS and Mac Catalyst, Poll(SelectError) doesn't report
out-of-band data, because XNU's poll() sets POLLPRI only with POLLHUP.
Say so in the Poll return values and the Select remarks.

Fixes dotnet/runtime#135995

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@caraioniurie47
caraioniurie47 requested a review from a team as a code owner November 7, 2026 10:12
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Socket.Poll(SelectError) does not report out-of-band data on macOS, iOS, tvOS and Mac Catalyst

1 participant