Async block creating thread memory leak on tomcat

Elements 8.3.93.1987
Visual Studio 2015 Shell (Integrated)
Version 14.0.23107.0 D14REL

Execution of async block appears to be creating a thread (Thread-10 in this case) which is not stopped when app is stopped. The app is a class library used within a tomcat webapp.

Problem occurs when this is executed:

  async begin
    mySessionId := 'async statement';
  end;

Below is the logging from tomcat upon stopping. The ‘endConnection: sessionID=async statement’ is logged by my app showing that the async block did execute.

“C:\Tomcat 8.0\bin\catalina.bat” stop
Disconnected from the target VM, address: ‘127.0.0.1:64176’, transport: ‘socket’
Using CATALINA_BASE: “C:\Users\REWalker.IntelliJIdea2016.3\system\tomcat\Unnamed_webfast_6”
Using CATALINA_HOME: “C:\Tomcat 8.0”
Using CATALINA_TMPDIR: “C:\Tomcat 8.0\temp”
Using JRE_HOME: “C:\Program Files\Java\jdk1.8.0_92”
Using CLASSPATH: “C:\Tomcat 8.0\bin\bootstrap.jar;C:\Tomcat 8.0\bin\tomcat-juli.jar”
24-Nov-2016 10:50:54.997 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
24-Nov-2016 10:50:54.997 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler [“http-nio-8282”]
24-Nov-2016 10:50:55.052 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler [“ajp-nio-8009”]
24-Nov-2016 10:50:55.103 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
endConnection: sessionID=async statement
24-Nov-2016 10:50:55.125 INFO [localhost-startStop-2] null.null WSEndpoint.OnClose-session.getId:0
24-Nov-2016 10:50:55.126 INFO [localhost-startStop-2] com.vlg.comm.websockets.WSEndpoint.close WSEndpoint.OnClose-CloseReason:CloseReason: code [1001], reason [The web application is stopping]
24-Nov-2016 10:50:55.127 INFO [localhost-startStop-2] com.ssi.enquesta.utils.web.ApplicationContextListener.contextDestroyed Context destroyed…

-----here’s the problem-----
24-Nov-2016 10:50:55.140 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoader.clearReferencesThreads The web application [/webfast] appears to have started a thread named [Thread-10] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)

24-Nov-2016 10:50:55.149 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler [“http-nio-8282”]
24-Nov-2016 10:50:55.229 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler [“ajp-nio-8009”]
24-Nov-2016 10:50:55.231 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler [“http-nio-8282”]
24-Nov-2016 10:50:55.232 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler [“ajp-nio-8009”]
Disconnected from server

Below is the log from stopping the app with the async block commented out. Notice no thread leak.

“C:\Tomcat 8.0\bin\catalina.bat” stop
Disconnected from the target VM, address: ‘127.0.0.1:64176’, transport: ‘socket’
Using CATALINA_BASE: “C:\Users\REWalker.IntelliJIdea2016.3\system\tomcat\Unnamed_webfast_6”
Using CATALINA_HOME: “C:\Tomcat 8.0”
Using CATALINA_TMPDIR: “C:\Tomcat 8.0\temp”
Using JRE_HOME: “C:\Program Files\Java\jdk1.8.0_92”
Using CLASSPATH: “C:\Tomcat 8.0\bin\bootstrap.jar;C:\Tomcat 8.0\bin\tomcat-juli.jar”
24-Nov-2016 10:56:48.556 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
24-Nov-2016 10:56:48.556 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler [“http-nio-8282”]
24-Nov-2016 10:56:48.610 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler [“ajp-nio-8009”]
24-Nov-2016 10:56:48.660 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
24-Nov-2016 10:56:48.669 INFO [localhost-startStop-1] com.vlg.comm.websockets.WSEndpoint.close WSEndpoint.OnClose-session.getId:0
24-Nov-2016 10:56:48.669 INFO [localhost-startStop-1] com.vlg.comm.websockets.WSEndpoint.close WSEndpoint.OnClose-CloseReason:CloseReason: code [1001], reason [The web application is stopping]
24-Nov-2016 10:56:48.669 INFO [localhost-startStop-1] com.ssi.enquesta.utils.web.ApplicationContextListener.contextDestroyed Context destroyed…
endConnection: sessionID=
24-Nov-2016 10:56:48.684 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler [“http-nio-8282”]
24-Nov-2016 10:56:48.774 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler [“ajp-nio-8009”]
24-Nov-2016 10:56:48.776 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler [“http-nio-8282”]
24-Nov-2016 10:56:48.779 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler [“ajp-nio-8009”]
Disconnected from server

I updated to the latest 8.395 build with no change.

what about 9.0?

Downloaded just now. Will give it a try and report back.

As I recall, I can always reinstall the older version for deployment work…right?

No change with version 9.0.97

correct.

Thanks, logged as bugs://76839

Any idea on when a fix for this might be available? I’d hate to have to abandon one of the best features of Oxygene…

Hi. I didn’t see your last post else i would have answered sooner. This isn’t really a leak. It’s “just” a running thread pool (ExecutorService in java terms), which can have 1 or more threads, but they’re not leaking, it keeps itself to a max and kills unused threads, eventually, as java doesn’t have a reusable thread pool built in. If there’s a hook in Servlets that gets notified before shutting down, you can call: Task.Threadpool.shutdownNow; to force it to shut down.

Unfortunately, there’s no hook we can use to detect if running in a servlet and if so, automatically shut it down. This thread should be running after all.

bugs://76839 got closed with status nochangereq.

bugs://i64642 was closed as fixed.

Logged as bugs://i64642.