Repository navigation
Description
Description
OSSupportTest.IOControl_SIOCATMARK_Unix_Success fails with Expected: 1 / Actual: 0 when the out-of-band byte reaches the client after the client has read the in-band byte.
After the server sends the in-band byte 42 and the out-of-band byte 43, the test spins until SIOCATMARK is 0. On Unix SIOCATMARK is already 0 right after Connect, before any data is sent (the test asserts it), so the spin can end before either byte has arrived:
// Socket connected but no data sent.
Assert.Equal(4, client.IOControl(IOControlCode.OobDataRead, null, siocatmarkResult));
Assert.Equal(0, BitConverter.ToInt32(siocatmarkResult, 0));
server.Send(new byte[] { 42 }, SocketFlags.None);
server.Send(new byte[] { 43 }, SocketFlags.OutOfBand);
// OOB data received, but read pointer not at mark.
Assert.True(SpinWait.SpinUntil(() =>
{
Assert.Equal(4, client.IOControl(IOControlCode.OobDataRead, null, siocatmarkResult));
return BitConverter.ToInt32(siocatmarkResult, 0) == 0;
}, 10_000));The client then reads 42 and asserts that the read pointer is at the mark. If 43 has not arrived yet, SIOCATMARK is still 0:
var received = new byte[1];
Assert.Equal(1, client.Receive(received));
Assert.Equal(42, received[0]);
// OOB data received, read pointer at mark.
Assert.Equal(4, client.IOControl(IOControlCode.OobDataRead, null, siocatmarkResult));
Assert.Equal(1, BitConverter.ToInt32(siocatmarkResult, 0));CI failures of this test with Expected: 1 / Actual: 0 were reported in 2020 and 2021 (#37181, #50748); the one failure listed there with a queue, on 2021-04-04 in both, was on OSX.1013.Amd64.Open. Both issues were closed for no recent failures.
Reproduction Steps
On Linux, as root, with gcc, iptables and libnetfilter-queue-dev installed and after ./build.sh clr+libs -rc Release, hold only the loopback TCP segments that carry the URG flag for 100 ms, so the out-of-band byte reaches the client after the in-band byte, and run the test. From the repo root, with delay-urg.c (below) in it:
gcc -O2 -o delay-urg delay-urg.c -lnetfilter_queue
./delay-urg 100 &
iptables -A OUTPUT -o lo -p tcp --tcp-flags URG URG -j NFQUEUE --queue-num 0 --queue-bypass
./.dotnet/dotnet build src/libraries/System.Net.Sockets/tests/FunctionalTests /t:Test "/p:XUnitOptions=-method System.Net.Sockets.Tests.OSSupportTest.IOControl_SIOCATMARK_Unix_Success"
iptables -D OUTPUT -o lo -p tcp --tcp-flags URG URG -j NFQUEUE --queue-num 0 --queue-bypass
kill %1delay-urg.c holds each packet queued to NFQUEUE 0 for the given number of milliseconds, then accepts it:
// Holds every packet handed to NFQUEUE queue 0 for <delay_ms> before accepting it.
// Build: gcc -O2 -o delay-urg delay-urg.c -lnetfilter_queue
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <linux/netfilter.h>
#include <libnetfilter_queue/libnetfilter_queue.h>
static useconds_t delay_us;
static int on_packet(struct nfq_q_handle *qh, struct nfgenmsg *msg, struct nfq_data *nfa, void *data)
{
struct nfqnl_msg_packet_hdr *ph = nfq_get_msg_packet_hdr(nfa);
uint32_t id = ph ? ntohl(ph->packet_id) : 0;
usleep(delay_us);
fprintf(stderr, "delay-urg: released packet %u\n", id);
return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
}
int main(int argc, char **argv)
{
if (argc != 2) { fprintf(stderr, "usage: %s <delay_ms>\n", argv[0]); return 2; }
delay_us = (useconds_t)atoi(argv[1]) * 1000;
struct nfq_handle *h = nfq_open();
if (!h) { perror("nfq_open"); return 1; }
struct nfq_q_handle *qh = nfq_create_queue(h, 0, &on_packet, NULL);
if (!qh) { perror("nfq_create_queue"); return 1; }
if (nfq_set_mode(qh, NFQNL_COPY_META, 0) < 0) { perror("nfq_set_mode"); return 1; }
char buf[4096] __attribute__((aligned));
int fd = nfq_fd(h);
fprintf(stderr, "delay-urg: holding URG segments for %s ms\n", argv[1]);
for (;;)
{
int n = recv(fd, buf, sizeof(buf), 0);
if (n < 0) { perror("recv"); return 1; }
nfq_handle_packet(h, buf, n);
}
}Without the iptables rule the test passes.
A Thread.Sleep between the two server.Send calls does not reproduce it: the test runs on one thread, so the client reads only after both bytes have been sent.
Expected behavior
The test passes however late the out-of-band byte arrives, within the test's 10 s timeout.
Actual behavior
The test fails at OSSupport.cs:151 (path and the reflection frames below the test trimmed):
System.Net.Sockets.Tests.OSSupportTest.IOControl_SIOCATMARK_Unix_Success [FAIL]
Assert.Equal() Failure: Values differ
Expected: 1
Actual: 0
Stack Trace:
src/libraries/System.Net.Sockets/tests/FunctionalTests/OSSupport.cs(151,0): at System.Net.Sockets.Tests.OSSupportTest.IOControl_SIOCATMARK_Unix_Success()
With the URG segments held for 20, 100 or 300 ms, it failed this way in every run.
Regression?
No. The spin was added in 891e8a71b4b ("Avoid timing issue in IOControl_SIOCATMARK tests (dotnet/corefx#27838)"); at that commit the Unix test already asserted SIOCATMARK == 0 after Connect, so the spin waited for a value that was already there.
Known Workarounds
Not applicable: only the test is affected.
Configuration
- dotnet/runtime
mainat 06b83f7,./build.sh clr+libs -rc Release(libraries in Debug), tests run on the built testhost (shared framework 12.0.0). - Ubuntu 22.04.5 LTS on WSL 2, Linux 6.18.40.1-microsoft-standard-WSL2, x64.
- The test runs on Unix only; the failure was reproduced on Linux and not tried elsewhere.
Other information
The Windows variant, IOControl_SIOCATMARK_Windows_Success, has the same spin, but that test asserts SIOCATMARK is 1 before any data is sent, so its wait for 0 does wait for the out-of-band byte:
// Socket connected but no data sent.
Assert.Equal(4, client.IOControl(IOControlCode.OobDataRead, null, siocatmarkResult));
Assert.Equal(1, BitConverter.ToInt32(siocatmarkResult, 0));
server.Send(new byte[] { 42 }, SocketFlags.None);
server.Send(new byte[] { 43 }, SocketFlags.OutOfBand);
// OOB data received, but read pointer not at mark
Assert.True(SpinWait.SpinUntil(() =>
{
Assert.Equal(4, client.IOControl(IOControlCode.OobDataRead, null, siocatmarkResult));
return BitConverter.ToInt32(siocatmarkResult, 0) == 0;
}, 10_000));I have the test change ready and will open a PR for it shortly. Could this be assigned to me?
Note
AI-generated, written at my direction and reviewed by me before posting.
Source read at dotnet/runtime 06b83f7.
Run on Ubuntu 22.04.5 LTS on WSL 2, Linux 6.18.40.1-microsoft-standard-WSL2 x64, testhost shared framework 12.0.0 built with ./build.sh clr+libs -rc Release.
Commands: the Reproduction Steps block above, as root (100 ms); the same test with no iptables rule and with the URG segments held for 20, 100 and 300 ms, each run repeatedly through the testhost's xunit.console.dll on the built test assembly, recording each failing run's assert and line; the same test with a 500 ms Thread.Sleep between the two server.Send calls and no iptables rule.
The Windows sentence comes from a Python probe on Windows 11 that calls Winsock's ioctlsocket(SIOCATMARK) on a loopback socket before any data, after the in-band byte and after the out-of-band byte (1, 1, 0); the .NET Windows test was not run.
Activity
dotnet-policy-service commentedon Oct 14, 2026
Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 14, 2026
Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
Wait for the OOB byte in IOControl_SIOCATMARK_Unix_Success (#135789)