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

java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b134

      Description

      java/net/MulticastSocket/NoLoopbackPackets.java starts a daemon thread which has an infinite loop. Looks like the loop may run forever:

      http://hg.openjdk.java.net/jdk9/dev/jdk/file/0cd4b4def24f/test/java/net/MulticastSocket/NoLoopbackPackets.java#l127

      ...
                  Thread sender = new Thread(new Sender(groups));
                  sender.setDaemon(true); // we want sender to stop when main thread exits
                  sender.start();
      ...
      static class Sender implements Runnable {
              private List<SocketAddress> sendToGroups;

              public Sender(List<SocketAddress> groups) {
                  sendToGroups = groups;
              }

              public void run() {
                  byte[] buf = "hello world".getBytes();
                  List<DatagramPacket> packets = new ArrayList<DatagramPacket>();

                  try {
                      for (SocketAddress group : sendToGroups) {
                          DatagramPacket packet = new DatagramPacket(buf, buf.length, group);
                          packets.add(packet);
                      }

                      MulticastSocket msock = new MulticastSocket();
                      msock.setLoopbackMode(true); // disable loopback mode
                      for (;;) {
                          for (DatagramPacket packet : packets) {
                              msock.send(packet);
                          }

                          Thread.sleep(1000); // 1 second
                      }
                  } catch (Exception e) {
                      throw new RuntimeException(e);
                  }
              }
          }
      ...

      The test shouldn't leave daemon threads when they finish. It may slow down further test execution a little bit because daemon threads consume some JVM resources. If other tests also leave daemon threads, it may cause intermittent failures of other tests which run in the same JVM. See for example JDK-8160642 and JDK-8162757. Sender daemon thread is in jstack output:

      "Thread-2012" #2141 daemon prio=5 os_prio=0 tid=0x00007fec3c2ad800 nid=0x740c waiting on condition [0x00007fec941dc000]
         java.lang.Thread.State: TIMED_WAITING (sleeping)
      at java.lang.Thread.sleep(java.base@9-ea/Native Method)
      at NoLoopbackPackets$Sender.run(NoLoopbackPackets.java:144)
      at java.lang.Thread.run(java.base@9-ea/Thread.java:843)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                asmotrak Artem Smotrakov
                Reporter:
                asmotrak Artem Smotrakov
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: