Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8263243

ServerSocketChannel.accept() returns SocketChannel with duplicate end point



    • Bug
    • Resolution: Not an Issue
    • P4
    • None
    • 11.0.10, 15.0.2, 17
    • core-libs
    • x86_64
    • linux


      Under load, a call to ServerSocketChannel.accept() can return an identical SocketChannel (same protocol, client IP/port and server IP/port) to the SocketChannel returned from the previous accept() call. This should not be possible.

      A test case is available at:

      The steps to reproduce are:
      - Start the NetworkTest java application
      - From separate console windows, run at least two instance of the following: `for i in {1..50}; do /opt/wrk/wrk -t 2 -c 1000 -d 5s --latency --timeout 1s --script ./myPost.lua http://localhost:8080/post; done`

      Adjust path to wrk as appropriate.

      There does appear to be a timing element to this test and running more instances of the above wrk loop in additional console windows may increase the likelihood of triggering the error.

      Sample output is attached.

      openjdk-17-console.txt shows that two SocketChannel instances were returned and both were for the same protocol, client IP/port and server IP/port combination. The client port is 33314

      openjdk-17.pcapng shows the wireshark capture of all traffic to server port 8080 during the test. Filtering for "tcp.port=33314" shows only a single network connection from that client port to the server.

      openjdk-17.hprof is the heap dump generated as soon as the error was detected. It shows two SocketChannel instances (NetworkTest.currentConnection and NetworkTest.previousConnection) both with client port 33314 as expected from the console output. An examination of the heap dump shows the SocketChannel instance have sequential file descriptors. Otherwise both appear to be identical. Both SocketChannels are valid and open.

      I have been able to recreate this with the latest:
      - OpenJDK Java 17 EA build
      - Adopt OpenJDK Java 15 release
      - Adopt OpenJDK Java 11 release
      - Adopt OpenJDK Java 8 release

      This issue was originally observed as part of the investigation into this Spring WebFlux / Apache Tomcat issue:


        1. myPost.lua
          0.1 kB
        2. openjdk-17.hprof
          7.14 MB
        3. openjdk-17.pcapng
          1.64 MB
        4. openjdk-17-console.txt
          0.4 kB
        5. openjdk-17-console-free-false.txt
          0.4 kB
        6. openjdk-17-free-false.hprof
          15.34 MB
        7. openjdk-17-free-false.pcapng
          1.53 MB
        8. server.c
          2 kB
        9. tcp4-params.txt
          2 kB



            michaelm Michael McMahon
            markt Mark Thomas
            0 Vote for this issue
            7 Start watching this issue