You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "jfclere (via GitHub)" <gi...@apache.org> on 2025/02/05 15:25:33 UTC

[PR] Arrange the timeout logic and values. [commons-daemon]

jfclere opened a new pull request, #238:
URL: https://github.com/apache/commons-daemon/pull/238

   Fix for https://issues.apache.org/jira/browse/DAEMON-468


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998297223


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1269,7 +1277,7 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
         }
         else {
             if (lstrcmpA(_jni_sclass, "java/lang/System") == 0) {
-                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 20 * 1000);
+                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);

Review Comment:
   That is a hint procrun gives to the windows service manager, it needs to be bigger than the time procrun needs to stop the service, otherwise an error is reported.
   According to the https://learn.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_status the hint time is the next time procrun will interact with the windows service manger. So ONE_MINUTE is just a arbitrary value... 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2682481683

   Hello @jfclere 
   How were all these changes tested?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998297223


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1269,7 +1277,7 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
         }
         else {
             if (lstrcmpA(_jni_sclass, "java/lang/System") == 0) {
-                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 20 * 1000);
+                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);

Review Comment:
   That is a hint procrun gives to the windows service manager, it needs to be bigger than the time procrun needs to stop the service, otherwise an error is reported.
   In fact it seems the code we have in reportServiceStatusE() needs some fixes, according to the https://learn.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_status the hint time is the next time procrun will interact with the windows service manger. So ONE_MINUTE is just a arbitrary value... 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1944372957


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +953,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {
+                /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+                /* We also add 15 seconds for the service logic */

Review Comment:
   Yes in fact the timeout is applied to the STOP command (which connect to the running service) and later to the loop that waits for the child processes to exit. A 15 seconds is added to allow procrun to communicate with windows service manager.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2073170497


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -42,6 +42,9 @@
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
 #define ONE_MINUTE    (60 * 1000)
+#define ONE_MINUTE_SEC 60
+#define TIMEFORSERVICEMANAGER 15

Review Comment:
   Oops I forgot to remove those unused defines.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2071893369


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -42,6 +42,9 @@
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
 #define ONE_MINUTE    (60 * 1000)
+#define ONE_MINUTE_SEC 60
+#define TIMEFORSERVICEMANAGER 15

Review Comment:
   'TIMEFORSERVICEMANAGER' is not a good name IMO, use underscores...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2087116921


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */

Review Comment:
   OK I will update the doc to explain with "the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop" in the --StopTimeout documentation description  and tell that an error is return if SO_STOPTIMEOUT is too small.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998381076


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1876,8 +1908,21 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit.");
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);
-        apxDestroyJvm(ONE_MINUTE);
-        /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+        if (!apxDestroyJvm(ONE_MINUTE)) {
+            /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+            apxLogWrite(APXLOG_MARK_DEBUG "Not using JAVA apxDestroyJvm did nothing");
+            DWORD count = SO_STOPTIMEOUT;
+            if (!count)
+                count = ONE_MINUTE_SEC;
+            do {

Review Comment:
   Correct we wait for any processes the service created.
   And then kill them.
   So I need to add a something to store the total time procrun has been waiting :-(



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2840966949

   I have merged all the commit and add tests for procrun.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2078220236


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1876,8 +1908,21 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit.");
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);
-        apxDestroyJvm(ONE_MINUTE);
-        /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+        if (!apxDestroyJvm(ONE_MINUTE)) {
+            /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+            apxLogWrite(APXLOG_MARK_DEBUG "Not using JAVA apxDestroyJvm did nothing");
+            DWORD count = SO_STOPTIMEOUT;
+            if (!count)
+                count = ONE_MINUTE_SEC;
+            do {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998511413


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +955,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {
+                /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+                /* We also add TIMEFORSERVICEMANAGER seconds for the service logic */
                 int i;
-                for (i = 0; i < timeout; i++) {
+                for (i = 0; i < (timeout*2+TIMEFORSERVICEMANAGER); i++) {

Review Comment:
   Agreed that makes more sense.
   Here we just need to wait for timeout, (so loop for timeout times) the service is another process where we need maximumFinishTime and currentTime.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2859804946

   I think a new PR. We can bring it in first and make sure all is well. @markt-asf wdyt?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2085067552


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -258,6 +259,8 @@ static BOOL   gSignalValid   = TRUE;
 static APXJAVA_THREADARGS gRargs;
 static APXJAVA_THREADARGS gSargs;
 
+static DWORD stopStarted = 0; /* Not stop not started */

Review Comment:
   fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2085082671


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1223,16 +1261,26 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
     BOOL   wait_to_die = FALSE;
     DWORD  timeout     = SO_STOPTIMEOUT * 1000;
     DWORD  dwCtrlType  = (DWORD)((BYTE *)lpParameter - (BYTE *)0);
+    DWORD  waited = 0;
 
     apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+    stopStarted = GetTickCount();
+    if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
+        timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
+    if (!timeout) {
+        /* Use 1 minutes default */

Review Comment:
   fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "markt-asf (via GitHub)" <gi...@apache.org>.
markt-asf commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2081081047


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -42,6 +42,7 @@
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
 #define ONE_MINUTE    (60 * 1000)
+#define ONE_MINUTE_SEC 60

Review Comment:
   `ONE_MINUTE_SEC` looks weird every time I look at it even when I know what it means. Maybe
   ```
   ONE_MINUTE_AS_MILLIS
   ONE_MINUTE_AS_SEC
   ```



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -258,6 +259,8 @@ static BOOL   gSignalValid   = TRUE;
 static APXJAVA_THREADARGS gRargs;
 static APXJAVA_THREADARGS gSargs;
 
+static DWORD stopStarted = 0; /* Not stop not started */

Review Comment:
   Comment looks odd. Does it mean the time that the stop process began? A rename might be helpful here. Maybe `stopCalledTime`?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+            for (i = 0; i < timeout; i=i+1000) {

Review Comment:
   `apxServiceCheckStop` will take at least 1000ms because of the wait. Is there any chance it could take longer than that? Should this loop use `waitedSinceStopCmd()` rather than `i`?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */

Review Comment:
   This is really useful information that should probably be in the docs. Does it make sense to use the same timeout for both?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1223,16 +1261,26 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
     BOOL   wait_to_die = FALSE;
     DWORD  timeout     = SO_STOPTIMEOUT * 1000;
     DWORD  dwCtrlType  = (DWORD)((BYTE *)lpParameter - (BYTE *)0);
+    DWORD  waited = 0;
 
     apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+    stopStarted = GetTickCount();
+    if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
+        timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
+    if (!timeout) {
+        /* Use 1 minutes default */

Review Comment:
   Drop the 's' from minutes.



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1375,11 +1418,18 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
         CloseHandle(gSignalThread);
         gSignalEvent = NULL;
     }
-    if (wait_to_die && !timeout)
-        timeout = 300 * 1000;   /* Use the 5 minute default shutdown */
 
-    if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
-        timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
+    /* We already waited here timeout is msec */
+    waited = waitedSinceStopCmd();
+    apxLogWrite(APXLOG_MARK_DEBUG "Waited %d timeout (%d)", waited, timeout);
+    if (timeout > waited) {
+        timeout = timeout - waited;
+    } else {
+        /* something is wrong, the timeout is too small */
+        apxLogWrite(APXLOG_MARK_DEBUG "Waiting more than the specified timeout (%d)", timeout);
+    }

Review Comment:
   Include how long we have waited in this message?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1838,8 +1859,9 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
         SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
 
         if (SO_STOPTIMEOUT) {
-            /* we have a stop timeout */
+            /* we wait for ever for the service to be done, printing a debug message every 2 seconds */

Review Comment:
   Maybe update the comment to reflect that? "for the service to be done" suggests "until the service has stopped" rather than "until the call to stop the service has returned".



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }

Review Comment:
   If we aren't ever going to allow an infinite timeout, why let users create one in the first place? Should we reject any attempt to create such a service? If we go that route, we'll need to allow for existing services that do have an infinite timeout. Should be log a warning that we are ignoring the timeout?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1609,11 +1659,14 @@ void WINAPI service_ctrl_handler(DWORD dwCtrlCode)
         case SERVICE_CONTROL_STOP:
             apxLogWrite(APXLOG_MARK_INFO "Service SERVICE_CONTROL_STOP signalled.");
             _exe_shutdown = TRUE;
-            if (SO_STOPTIMEOUT > 0) {
+            stopStarted = GetTickCount();
+            /* hint for shutdown time */
+            if (SO_STOPTIMEOUT) {
                 reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, SO_STOPTIMEOUT * 1000);
             }
             else {
-                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3 * 1000);
+                /* Use 1 minutes default */

Review Comment:
   s/minutes/minute/



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998297223


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1269,7 +1277,7 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
         }
         else {
             if (lstrcmpA(_jni_sclass, "java/lang/System") == 0) {
-                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 20 * 1000);
+                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);

Review Comment:
   That is a hint procrun gives to the windows service manager, it needs to be bigger than the time procrun needs to stop the service, otherwise an error is reported.
   But yes it could depend on the timeout.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "markt-asf (via GitHub)" <gi...@apache.org>.
markt-asf commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1983049640


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +955,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {

Review Comment:
   `timeout` cannot be zero here this this will always be `true`. Therefore, no need for the `if` statement.



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +955,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {

Review Comment:
   Why not `<=` here?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +955,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {
+                /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+                /* We also add TIMEFORSERVICEMANAGER seconds for the service logic */
                 int i;
-                for (i = 0; i < timeout; i++) {
+                for (i = 0; i < (timeout*2+TIMEFORSERVICEMANAGER); i++) {

Review Comment:
   This makes the minimum timeout 17s. That seems high to me.
   
   I would expect to set a timeout for the total time (sending the stop command, waiting for the service to stop, overhead). How practical is to set set a `maximumFinishTime` here of `currentTime + timeout` and then calculate the `timeout`  as `maximumFinishTime - currentTime` whenever a timeout is required?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1887,7 +1932,7 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting for all threads to exit.");
         apxDestroyJvm(INFINITE);
-        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);

Review Comment:
   Why hard-coded to a minute?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1838,8 +1859,9 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
         SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
 
         if (SO_STOPTIMEOUT) {
-            /* we have a stop timeout */
+            /* we wait for ever for the service to be done, printing a debug message every 2 seconds */

Review Comment:
   Doesn't this wait for `timeout` seconds rather than waiting forever?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1876,8 +1908,21 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit.");
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);
-        apxDestroyJvm(ONE_MINUTE);
-        /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+        if (!apxDestroyJvm(ONE_MINUTE)) {
+            /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+            apxLogWrite(APXLOG_MARK_DEBUG "Not using JAVA apxDestroyJvm did nothing");
+            DWORD count = SO_STOPTIMEOUT;
+            if (!count)
+                count = ONE_MINUTE_SEC;
+            do {

Review Comment:
   This looks like a possible 3rd wait using the stop timeout.



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1269,7 +1277,7 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
         }
         else {
             if (lstrcmpA(_jni_sclass, "java/lang/System") == 0) {
-                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 20 * 1000);
+                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);

Review Comment:
   Why is this hard-coded? Shouldn't it depend on the timeout?



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1380,7 +1388,10 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
 
     if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
         timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
-    reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, timeout);
+    if (timeout)
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, timeout);
+    else
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE_SEC);
 
     if (timeout) {
         FILETIME fts, fte;

Review Comment:
   Again, isn't timeout now always >0 ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2087106832


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }

Review Comment:
   OK I have fixed to reject any attempt to create such a service.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "markt-asf (via GitHub)" <gi...@apache.org>.
markt-asf commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2086496358


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+            for (i = 0; i < timeout; i=i+1000) {

Review Comment:
   OK. I'd probably go with `waitedSinceStopCmd()` anyway but I'm not going to object to this approach.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "sebbASF (via GitHub)" <gi...@apache.org>.
sebbASF commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1944335695


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +953,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {
+                /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+                /* We also add 15 seconds for the service logic */

Review Comment:
   Is that the reason for the *2 below? I assume so, but I could be wrong.



##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +953,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {
+                /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+                /* We also add 15 seconds for the service logic */
                 int i;
-                for (i = 0; i < timeout; i++) {
+                for (i = 0; i < (timeout*2+15); i++) {
+                    /* apxServiceCheckStop waits 1000 ms */

Review Comment:
   The magic number 15 should have a define.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "markt-asf (via GitHub)" <gi...@apache.org>.
markt-asf commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2859911406

   That works for me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1999348617


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1838,8 +1859,9 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
         SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
 
         if (SO_STOPTIMEOUT) {
-            /* we have a stop timeout */
+            /* we wait for ever for the service to be done, printing a debug message every 2 seconds */

Review Comment:
   We need to wait for ever until a stop service is issued and there we wait for the timeout...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998381076


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1876,8 +1908,21 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit.");
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);
-        apxDestroyJvm(ONE_MINUTE);
-        /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+        if (!apxDestroyJvm(ONE_MINUTE)) {
+            /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+            apxLogWrite(APXLOG_MARK_DEBUG "Not using JAVA apxDestroyJvm did nothing");
+            DWORD count = SO_STOPTIMEOUT;
+            if (!count)
+                count = ONE_MINUTE_SEC;
+            do {

Review Comment:
   Yes we are trying to kill any processes we created in that case.
   So I need to add a something to store the total time procrun has been waiting :-(
   And hope that the timeout is big enough to make sure the processes cleaning is done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2763802267

   @jfclere 
   The build breaks due to what looks like a missing Apache header. Make sure to build locally before you push.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2753631019

   @markt-asf @garydgregory I have looked to how to test procrun the most easy is a bat script that install/start/stop/deinstall a dummy service (in java) that waits based on a simple text command (a number seems to be enough).
   Should I go forward or look for something else?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2694759197

   @garydgregory By hands on a windows VS2019, you may create an issue to think about automated tests...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2086433148


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+            for (i = 0; i < timeout; i=i+1000) {

Review Comment:
   According to my tests QueryServiceStatus() returns immediately  even on a slow VM.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2859738310

   @markt-asf @garydgregory I have prepared a github workflow to test the windows native builds, should I merge this PR and create a new one, or add it to this one.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r1998511413


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -952,9 +955,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
         if (!rv) {
             /* Wait for the timeout if any */
             int  timeout     = SO_STOPTIMEOUT;
+            if (timeout == 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
             if (timeout) {
+                /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */
+                /* We also add TIMEFORSERVICEMANAGER seconds for the service logic */
                 int i;
-                for (i = 0; i < timeout; i++) {
+                for (i = 0; i < (timeout*2+TIMEFORSERVICEMANAGER); i++) {

Review Comment:
   Agreed that makes more sense.
   Here we just need to wait for timeout, the service is another process where we need maximumFinishTime and currentTime.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2078259386


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -1887,7 +1932,7 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting for all threads to exit.");
         apxDestroyJvm(INFINITE);
-        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);

Review Comment:
   ONE_MINUTE is using in other place and 0 looks wrong, that a hint value for service manager so I don't think that is a problem and there are other location with ONE_MINUTE.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2085077195


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */

Review Comment:
   @markt-asf so you are suggesting to document how to debug the timeout, in the case value is too small?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "markt-asf (via GitHub)" <gi...@apache.org>.
markt-asf commented on code in PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#discussion_r2085086943


##########
src/native/windows/apps/prunsrv/prunsrv.c:
##########
@@ -951,15 +970,34 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
                                NULL);
         if (!rv) {
             /* Wait for the timeout if any */
-            int  timeout     = SO_STOPTIMEOUT;
-            if (timeout) {
-                int i;
-                for (i = 0; i < timeout; i++) {
-                    rv = apxServiceCheckStop(hService);
-                    apxLogWrite(APXLOG_MARK_DEBUG "apxServiceCheck returns %d.", rv);
-                    if (rv)
-                        break;
-                }
+            int timeout     = SO_STOPTIMEOUT;
+            int waited      = waitedSinceStopCmd();
+            int i;
+            if (timeout <= 0) {
+                /* waiting for ever doesn't look OK here */
+                timeout = ONE_MINUTE_SEC;
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService Waited %d timeout %d", waited, timeout*1000);
+            if (timeout*1000 > waited) {
+                /*
+                 * it took waited to send the command, the service starts
+                 * counting the timeout once it receives the STOP command
+                 * that is probably after waited but that depends on the
+                 * box we are using, we add 1 second just to be sure.
+                 */
+                timeout = timeout*1000 + waited + 1000;
+            } else {
+                apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService timeout %d too small.", timeout*1000);
+                timeout = 1000; /* we might wait 1 s too much but we check if we have already stopped */
+            }
+            apxLogWrite(APXLOG_MARK_DEBUG "docmdStopService estimated timeout %d milliseconds.", timeout);
+            /* the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop */

Review Comment:
   I meant to highlight the `the SO_STOPTIMEOUT applies to the stop command and to the time service needs to stop` comment. Assuming the stop command any return before the service has stopped.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "markt-asf (via GitHub)" <gi...@apache.org>.
markt-asf commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2639062365

   The documentation also needs to be updated to reflect all of these changes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Arrange the timeout logic and values. [commons-daemon]

Posted by "jfclere (via GitHub)" <gi...@apache.org>.
jfclere commented on PR #238:
URL: https://github.com/apache/commons-daemon/pull/238#issuecomment-2682471130

   @sebbASF I did the changes you requested @markt-asf I have adjusted the doc, should I merge now?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org