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

(sctp) JDK-7118373 is not fixed for SctpChannel

    XMLWordPrintable

Details

    • b17
    • x86
    • linux_redhat_7.3
    • Verified

    Backports

      Description

                                        
        ADDITIONAL SYSTEM INFORMATION :
        OS:
        Red Hat Linux 7.4 Linux 3.10.0-693.el7.x86_64 #1 SMP

        Java:
        openjdk version "14-ea" 2020-03-17
        OpenJDK Runtime Environment (build 14-ea+20-879)
        OpenJDK 64-Bit Server VM (build 14-ea+20-879, mixed mode, sharing)

        A DESCRIPTION OF THE PROBLEM :
        JDK-7118373 is fixed for SocketChannel in JDK8, but is not fixed for SctpChannel in latest
        JDK release (JDK 14-ea+20).


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Run test case as background process.
          java ESctp &
        2. Repleat to invoke "lsof -U -a -p [PID]" during running above process

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Number of unix socket keeps 1
        ACTUAL -
        Number of unix socket increases linearly

        ---------- BEGIN SOURCE ----------
        import java.net.*;
        import java.util.*;
        import java.io.*;
        import java.nio.channels.*;
        import com.sun.nio.sctp.*;

        class ESctp
        {
          static Selector selector;
          static int NUM = 10;
          static SelectorThread selthread;

          public static void main(String[] args) throws Exception
          {
            int port = 12345;

            if (!isSCTPSupported()) {
              System.out.println("SCTP protocol is not supported");
              System.out.println("Test cannot be run");
              return;
            }

            if (args.length == 1) {
              try {
                port = Integer.parseInt(args[0]);
              } catch(Exception e) {}
            }
            new Server(port).start();

            new Server2(port+1).start();
            Thread.sleep(100); // wait for server ready
            selector = Selector.open();

            init(port+1);

            selthread = new SelectorThread();
            selthread.start();

            for (int i = 0 ; i < 500 ; ++i) {
              System.out.println(i);
              doIt(port);
              Thread.sleep(200);
            }
            System.out.println("end");
            System.exit(0);
          }

          static boolean isSCTPSupported() {
            try {
              SctpChannel c = SctpChannel.open();
              c.close();
              return true;
            } catch (IOException ioe) {
              ioe.printStackTrace();
            } catch (UnsupportedOperationException e) {
              System.out.println(e);
            }

            return false;
          }

          static void init(int port) throws Exception
          {
            InetSocketAddress sa = new InetSocketAddress("localhost", port);
            for (int i = 0 ; i < 3 ; ++i) {
              SctpChannel channel = SctpChannel.open(sa, 1, 1);
              channel.configureBlocking(false);
              channel.register(selector, SelectionKey.OP_READ);
            }
          }


          static void doIt(int port) throws Exception
          {
            InetSocketAddress sa = new InetSocketAddress("localhost", port);

            for (int i = 0 ; i < NUM ; ++i) {
              System.out.println(" " + i);
              SctpChannel channel = SctpChannel.open(sa, 1, 1);
              channel.configureBlocking(false);

              SelectionKey key = selthread.regchannel(channel);

              key.cancel();
              selector.wakeup();
              channel.close();

              Thread.sleep(200);
            }
          }

          static class SelectorThread extends Thread
          {
            Object lock = new Object();
            SctpChannel channel;
            SelectionKey key;

            SelectionKey regchannel(SctpChannel ch) throws Exception
            {
              synchronized (lock) {
        channel = ch;
        selector.wakeup();
        lock.wait();
              }
              return key;
            }

            public void run()
            {
              try {
                while (true) {
        selector.select(10000);
        synchronized (lock) {
        if (channel != null) {
        key = channel.register(selector, SelectionKey.OP_READ);
        channel = null;
        lock.notify();
        }
        }
                }

              } catch (Exception e) {
        e.printStackTrace();
              }
            }
          }

          static class Server2 extends Thread
          {
            SctpChannel[] x;
            int port;

            Server2(int port) {
              this.port = port;
            }

            public void run()
            {
              x = new SctpChannel[32];
              int i = 0;
              try {
        SctpServerChannel ss = SctpServerChannel.open();
        InetSocketAddress sa = new InetSocketAddress("localhost", port);
        ss.bind(sa);
        while (true) {
        SctpChannel soc = ss.accept();
                  x[i] = soc;
                  i++;
        }
              } catch (Exception e) {
        e.printStackTrace();
              }
            }
          }
            
          static class Server extends Thread
          {
            int port;

            Server(int port) { this.port = port; }

            public void run()
            {
              try {
        SctpServerChannel ss = SctpServerChannel.open();
        InetSocketAddress sa = new InetSocketAddress("localhost", port);
        ss.bind(sa);
        while (true) {
        SctpChannel soc = ss.accept();
        soc.close();
        }
              } catch (Exception e) {
        e.printStackTrace();
              }
            }
          }
        }


        ---------- END SOURCE ----------

        FREQUENCY : rarely

        Attachments

          Issue Links

            Activity

              People

                chegar Chris Hegarty
                tongwan Andrew Wang
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: