Skip to content

Commit

Permalink
Disable port sharing mechanisms when running in single processor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Sep 3, 2024
1 parent d5c2ac5 commit 5b23be7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,8 @@ CxPlatSocketContextInitialize(
// Only set SO_REUSEPORT on a server socket, otherwise the client could be
// assigned a server port (unless it's forcing sharing).
//
if (Config->Flags & CXPLAT_SOCKET_FLAG_SHARE || Config->RemoteAddress == NULL) {
if ((Config->Flags & CXPLAT_SOCKET_FLAG_SHARE || Config->RemoteAddress == NULL) &&
SocketContext->Binding->Datapath->PartitionCount > 1) {
//
// The port is shared across processors.
//
Expand Down
2 changes: 1 addition & 1 deletion src/platform/datapath_winuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ SocketCreateUdp(
goto Error;
}

if (Config->RemoteAddress == NULL) {
if (Config->RemoteAddress == NULL && Datapath->PartitionCount > 1) {
uint16_t Processor = i; // API only supports 16-bit proc index.
Result =
WSAIoctl(
Expand Down
17 changes: 17 additions & 0 deletions src/platform/unittest/DataPathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,23 @@ TEST_P(DataPathTest, MultiBindListener) {
ASSERT_EQ(QUIC_STATUS_ADDRESS_IN_USE, Server2.GetInitStatus());
}

TEST_P(DataPathTest, MultiBindListenerSingleProcessor) {
UdpRecvContext RecvContext;
QUIC_EXECUTION_CONFIG Config = { QUIC_EXECUTION_CONFIG_FLAG_NO_IDEAL_PROC, UINT32_MAX, 1, 0 };
CxPlatDataPath Datapath(&UdpRecvCallbacks, nullptr, 0, &Config);

auto ServerAddress = GetNewLocalAddr();
CxPlatSocket Server1(Datapath, &ServerAddress.SockAddr, nullptr, &RecvContext);
while (Server1.GetInitStatus() == QUIC_STATUS_ADDRESS_IN_USE) {
ServerAddress.SockAddr.Ipv4.sin_port = GetNextPort();
Server1.CreateUdp(Datapath, &ServerAddress.SockAddr, nullptr, &RecvContext);
}
VERIFY_QUIC_SUCCESS(Server1.GetInitStatus());

CxPlatSocket Server2(Datapath, &ServerAddress.SockAddr, nullptr, &RecvContext);
ASSERT_EQ(QUIC_STATUS_ADDRESS_IN_USE, Server2.GetInitStatus());
}

TEST_F(DataPathTest, TcpListener)
{
CxPlatDataPath Datapath(nullptr, &EmptyTcpCallbacks);
Expand Down

0 comments on commit 5b23be7

Please sign in to comment.