Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DualModeAcceptAsync.AcceptAsyncV6BoundToAnyV4_CantConnect failed in CI #19162

Closed
stephentoub opened this issue Nov 1, 2016 · 6 comments
Closed
Labels
area-System.Net.Sockets disabled-test The test is disabled in source code against the issue test-run-core Test failures in .NET Core test runs
Milestone

Comments

@stephentoub
Copy link
Member

https://ci.dot.net/job/dotnet_corefx/job/master/job/ubuntu14.04_release_prtest/2476/consoleText

System.Net.Sockets.Tests.DualModeAcceptAsync.AcceptAsyncV6BoundToAnyV4_CantConnect [FAIL]
        Assert.Throws() Failure
        Expected: typeof(System.Net.Sockets.SocketException)
        Actual:   typeof(System.TimeoutException): Timed out while waiting for the server accept...
        Stack Trace:
           /mnt/j/workspace/dotnet_corefx/master/ubuntu14.04_release_prtest/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs(976,0): at System.Net.Sockets.Tests.DualModeAcceptAsync.DualModeConnect_AcceptAsync_Helper(IPAddress listenOn, IPAddress connectTo)
@davidsh davidsh self-assigned this Nov 1, 2016
@davidsh
Copy link
Contributor

davidsh commented Nov 1, 2016

I will disable the test for now.

@davidsh davidsh removed their assignment Nov 1, 2016
@steveharter steveharter self-assigned this Feb 28, 2017
@steveharter
Copy link
Member

Fix is to disable such tests on non-Windows. Loopback IPV4 and Loopback IPV6 considered separate addresses and on Linux it is easy to get both to exist as separate connections with same port.

@AriNuer
Copy link

AriNuer commented Aug 16, 2019

Test System.Net.Sockets.Tests.DualModeAcceptAsync.AcceptAsyncV6BoundToAnyV4_CantConnect failed with similar exception:

    System.Net.Sockets.Tests.DualModeAcceptAsync.AcceptAsyncV6BoundToAnyV4_CantConnect [FAIL]
      Assert.Throws() Failure
      Expected: typeof(System.Net.Sockets.SocketException)
      Actual:   typeof(System.TimeoutException): Timed out while waiting for either of client and server connections...
      ---- System.TimeoutException : Timed out while waiting for either of client and server connections...
      Stack Trace:
        /_/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs(973,0): at System.Net.Sockets.Tests.DualModeAcceptAsync.DualModeConnect_AcceptAsync_Helper(IPAddress listenOn, IPAddress connectTo)
        /_/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs(934,0): at System.Net.Sockets.Tests.DualModeAcceptAsync.<AcceptAsyncV6BoundToAnyV4_CantConnect>b__6_0()
        ----- Inner Stack Trace -----
        /_/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs(973,0): at System.Net.Sockets.Tests.DualModeAcceptAsync.DualModeConnect_AcceptAsync_Helper(IPAddress listenOn, IPAddress connectTo)
        /_/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs(934,0): at System.Net.Sockets.Tests.DualModeAcceptAsync.<AcceptAsyncV6BoundToAnyV4_CantConnect>b__6_0()
  Finished:    System.Net.Sockets.Tests
=== TEST EXECUTION SUMMARY ===
   System.Net.Sockets.Tests  Total: 958, Errors: 0, Failed: 1, Skipped: 9, Time: 65.515s
----- end Fri 08/16/2019  6:50:00.96 ----- exit code 1 ----------------------------------------------------------

Build: -20190815(Master)

Details:
https://helix.dot.net/api/2019-06-17/jobs/ca00932e-ead4-406d-8275-a9eb70421e41/workitems/System.Net.Sockets.Tests/console

@ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer reopened this Aug 16, 2019
@steveharter steveharter removed their assignment Aug 19, 2019
@steveharter
Copy link
Member

FWIW I dug up my old POSIX repro that shows port collisions are possible across protocols; this should only repro on Unix although with enough iterations to cycle around past 65,535 could also occur on Windows (haven't verified).

It asks for a port using Ipv6 and then loops 10,000 times to see if the same port number can be assigned for Ipv4.

Not tested here but you can have both UDP vs TCP on same protocol (IPV4) using the same port, meaning collisions are possible that way too.

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/socket.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

static int CreateIpv4Socket(bool closeSocket, int portToUse)
{
       struct sockaddr_in serv_addr;

       int sockfd = socket(AF_INET, SOCK_STREAM, 0);
       if (sockfd < 0)
       {
              perror("ERROR opening socket");
              exit(1);
       }

       bzero((char *)&serv_addr, sizeof(serv_addr));

       serv_addr.sin_family = AF_INET;
       serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
       if (portToUse == 0)
       {
              serv_addr.sin_port = 0;
       }
       else
       {
              serv_addr.sin_port = htons(portToUse);
       }

       if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
              perror("ERROR on binding");
              exit(1);
       }

       struct sockaddr_in out_addr;
       socklen_t len = sizeof(out_addr);
       if (getsockname(sockfd, (struct sockaddr *)&out_addr, &len) == -1) {
              perror("getsockname");
              exit(1);
       }

       int portUsed = out_addr.sin_port;

       if (closeSocket)
              close(sockfd);

       return portUsed;
}

static int CreateIpv6Socket(bool closeSocket, int portToUse)
{
       struct sockaddr_in6 serv_addr;

       int sockfd = socket(AF_INET6, SOCK_STREAM, 0);
       if (sockfd < 0)
       {
              perror("ERROR opening socket2");
              exit(1);
       }

       bzero((char *)&serv_addr, sizeof(serv_addr));

       serv_addr.sin6_family = AF_INET6;
       serv_addr.sin6_addr = in6addr_loopback;
       if (portToUse == 0)
       {
              serv_addr.sin6_port = 0;
       }
       else
       {
              serv_addr.sin6_port = htons(portToUse);
       }

       if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
       {
              perror("ERROR on binding2");
              exit(1);
       }

       struct sockaddr_in6 addr_in6;
       socklen_t len2 = sizeof(addr_in6);
       if (getsockname(sockfd, (struct sockaddr *)&addr_in6, &len2) == -1)
       {
              perror("getsockname2");
              exit(1);
       }

       int portUsed = addr_in6.sin6_port;

       if (closeSocket)
              close(sockfd);

       return portUsed;
}

int main(int argc, char *argv[])
{
       int port = CreateIpv6Socket(false, 0);
       for (int i = 0; i < 10000; i++)
       {
              int port2 = CreateIpv4Socket(true, 0);
              printf("count: %d\tport number %d\t; original:%d\n", i, ntohs(port2), ntohs(port));

              if (port == port2)
              {
                     perror("DUPLICATE SOCKET. STOPPING");
                     exit(1);
              }
       }

       return 0;
}

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@karelz karelz modified the milestones: 5.0, Future May 7, 2020
@antonfirsov
Copy link
Member

No recent Windows failures, stabilization & re-enabling is covered by #1481.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2022
@karelz karelz modified the milestones: Future, 8.0.0 Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Sockets disabled-test The test is disabled in source code against the issue test-run-core Test failures in .NET Core test runs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants