Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrange the timeout logic and values. #238

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jfclere
Copy link
Contributor

@jfclere jfclere commented Feb 5, 2025

@markt-asf
Copy link
Contributor

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

Copy link
Contributor

@sebbASF sebbASF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments and define

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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jfclere
Copy link
Contributor Author

jfclere commented Feb 25, 2025

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

@garydgregory
Copy link
Member

Hello @jfclere
How were all these changes tested?

@jfclere
Copy link
Contributor Author

jfclere commented Mar 3, 2025

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

Copy link
Contributor

@markt-asf markt-asf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these changes are improvements to debug logging and could probably be made independently of this PR. That may make this PR simpler to review if it is just focused on the logic changes to shutdown.

The additional comments were welcome.

I think it would be better from a user perspective (if is possible) for the user to set the total timeout and procrun to then figure out what timeouts to use at each stage.

if (timeout == 0) {
/* waiting for ever doesn't look OK here */
timeout = ONE_MINUTE_SEC;
}
if (timeout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -952,9 +955,16 @@ static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
if (!rv) {
/* Wait for the timeout if any */
int timeout = SO_STOPTIMEOUT;
if (timeout == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not <= here?

int i;
for (i = 0; i < timeout; i++) {
for (i = 0; i < (timeout*2+TIMEFORSERVICEMANAGER); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this hard-coded? Shouldn't it depend on the 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, isn't timeout now always >0 ?

@@ -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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this wait for timeout seconds rather than waiting forever?

Comment on lines +1914 to +1917
DWORD count = SO_STOPTIMEOUT;
if (!count)
count = ONE_MINUTE_SEC;
do {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hard-coded to a minute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants