WindhoverLabs / SLE-Provider-Simulator-

0 stars 0 forks source link

Memory Leak in StreamFrameSource #1

Open lorenzo-gomez-windhover opened 1 year ago

lorenzo-gomez-windhover commented 1 year ago
19:03:24.591 _global [30] CrashHandler type: UncaughtException, msg: Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[UdpTcDataLink-tc_simlink,5,main]: []
19:03:24.590 _global [35] YamcsServer Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Thread-9,10,main]: [java.base/java.util.Arrays.copyOf(Arrays.java:3689), java.base/java.util.ArrayList.grow(ArrayList.java:238), java.base/java.util.ArrayList.grow(ArrayList.java:243), java.base/java.util.ArrayList.add(ArrayList.java:486), java.base/java.util.ArrayList.add(ArrayList.java:499), org.yamcs.jsle.provider.RafServiceProvider.sendFrame(RafServiceProvider.java:227), com.windhoverlabs.yamcs.sle.simulator.StreamFrameSource.lambda$run$0(StreamFrameSource.java:124), com.windhoverlabs.yamcs.sle.simulator.StreamFrameSource$$Lambda$253/0x00000008403d8040.accept(Unknown Source), java.base/java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:807), com.windhoverlabs.yamcs.sle.simulator.StreamFrameSource.run(StreamFrameSource.java:122), java.base/java.lang.Thread.run(Thread.java:829)]
19:03:24.591 _global [35] CrashHandler type: UncaughtException, msg: Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Thread-9,10,main]: [java.base/java.util.Arrays.copyOf(Arrays.java:3689), java.base/java.util.ArrayList.grow(ArrayList.java:238), java.base/java.util.ArrayList.grow(ArrayList.java:243), java.base/java.util.ArrayList.add(ArrayList.java:486), java.base/java.util.ArrayList.add(ArrayList.java:499), org.yamcs.jsle.provider.RafServiceProvider.sendFrame(RafServiceProvider.java:227), com.windhoverlabs.yamcs.sle.simulator.StreamFrameSource.lambda$run$0(StreamFrameSource.java:124), com.windhoverlabs.yamcs.sle.simulator.StreamFrameSource$$Lambda$253/0x00000008403d8040.accept(Unknown Source), java.base/java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:807), com.windhoverlabs.yamcs.sle.simulator.StreamFrameSource.run(StreamFrameSource.java:122), java.base/java.lang.Thread.run(Thread.java:829)]

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-10"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Tablespace-simlink"
19:05:15.364 _global [13] YamcsServer Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Tablespace-_global,5,main]: []
19:05:15.364 _global [14] YamcsServer Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Tablespace-fsw,5,main]: []
19:05:15.366 _global [16] YamcsServer Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Processor-fsw.realtime,5,main]: []
19:05:15.366 _global [14] CrashHandler type: UncaughtException, msg: Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Tablespace-fsw,5,main]: []
19:05:15.366 _global [16] CrashHandler type: UncaughtException, msg: Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Processor-fsw.realtime,5,main]: []
19:05:15.366 _global [13] CrashHandler type: UncaughtException, msg: Uncaught exception 'java.lang.OutOfMemoryError: Java heap space' in thread Thread[Tablespace-_global,5,main]: []
lorenzo-gomez-windhover commented 1 year ago

I think this is because we are always sending frames from the stream:

    //    logger.info(": listening for UDP frames at port " + port);
    while (!stopping) {
      int dataLinkContinuity;
      dataLinkContinuity = 0; // no frame missing
      //   logger.fine("received datagram of size " + datagram.getLength());
      Instant t = Instant.now();
      CcsdsTime tc = CcsdsTime.fromUnix(t.getEpochSecond(), t.getNano());

      rsps.forEach(
          rsp ->
              rsp.sendFrame(
                  tc,
                  FrameQuality.good,
                  dataLinkContinuity,
                  currentPacket,
                  0,
                  512)); // using this for testing purposes ; not the best way to do this //
      // currentPacket.length()
    }

And the garbage collector does not get a chance to free the allocations. It needs to be throttled somehow....