This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new 285ac9c  Fix DAEMON-460. Protect against high CPU usage in JVM mode if 
start returns before stop is called.
285ac9c is described below

commit 285ac9c258917ef5265eb240583d0984cc5e4ed9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Dec 10 10:10:21 2024 +0000

    Fix DAEMON-460. Protect against high CPU usage in JVM mode if start returns 
before stop is called.
---
 src/changes/changes.xml                   |  6 ++++++
 src/native/windows/apps/prunsrv/prunsrv.c | 10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 110ebaa..c145e5f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,6 +45,12 @@
       <action dev="michaelo" type="fix">
         Fix several issues around Java OS and header files location detection.
       </action>
+      <!-- Add -->
+      <action issue="DAEMON-460" dev="markt" type="add">
+        Add protection to avoid high CPU usage for applications running in JVM
+        mode that do not wait for the stop method to be called before the start
+        method returns.
+      </action>
       <!-- UPDATE -->
       <action dev="ggregory" type="update" due-to="Dependabot">
         Bump org.apache.commons:commons-parent from 71 to 78 #189, #196, #198, 
#204, #207, #210, #216.
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c 
b/src/native/windows/apps/prunsrv/prunsrv.c
index a30417c..42c030d 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -1839,9 +1839,17 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
 
         if (SO_STOPTIMEOUT) {
             /* we have a stop timeout */
+            BOOL bLoopWarningIssued = FALSE;
             do {
                 /* wait 2 seconds */
-                apxHandleWait(gWorker, 2000, FALSE);
+                DWORD rv = apxHandleWait(gWorker, 2000, FALSE);
+                if (rv == WAIT_OBJECT_0 && !_exe_shutdown) {
+                    if (!bLoopWarningIssued) {
+                        apxLogWrite(APXLOG_MARK_WARN "Start method returned 
before stop method was called. This should not happen. Using loop with a fixed 
sleep of 2 seconds waiting for stop method to be called.");
+                        bLoopWarningIssued = TRUE;
+                    }
+                    Sleep(2000);
+                }
             } while (!_exe_shutdown);
             apxLogWrite(APXLOG_MARK_DEBUG "waiting %d sec... shutdown: %d", 
SO_STOPTIMEOUT, _exe_shutdown);
             apxHandleWait(gWorker, SO_STOPTIMEOUT*1000, FALSE);

Reply via email to