[
https://issues.apache.org/jira/browse/DAEMON-288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16063389#comment-16063389
]
Mike Miller commented on DAEMON-288:
------------------------------------
Based on DAEMON-366 traces and config, I think the main thread didn't see
gShutdownEvent because the start method returned before the stop method was
called. Notice the trace "Waiting for all threads to exit" occurred right
after the start was called. The stop wasn't called for another 3 minutes.
Since gShutdownEvent is created during the stop, it would have still been NULL
if the start exited before the serviceStop() was called. Since start exited
prematurely, the code ended up in the code path to INFINITE wait for the JVM to
exit. I would speculate that there was a non-daemon JVM thread preventing the
JVM from exiting. According to Procrun documentation, "Note: in jvm mode, the
start method should not return until the stop method has been called.".
Maybe a warning should be logged if executing in JVM mode and the start method
returns before the stop method is executed?
> Hang while stopping procrun service
> -----------------------------------
>
> Key: DAEMON-288
> URL: https://issues.apache.org/jira/browse/DAEMON-288
> Project: Commons Daemon
> Issue Type: Bug
> Components: Procrun
> Affects Versions: 1.0.13
> Environment: Windows 7 64 bit
> Reporter: Mike Miller
> Fix For: 1.0.15
>
> Attachments: prunsrv.c.patch
>
>
> There is a hang of the procrun service while it is attempting to stop. It is
> not easy to reproduce ( 30%-5% depending on pc ). Using a debugging to
> analyze the hang, both the serviceMain() and serviceStop() threads appear to
> have run and exited. I can tell this from the state of the global variables
> like gSargs and gShutdownEvents. Looking at the code, both are calling
> reportServiceStatus( SERVICE_STOPPED...). Typically when either one reports
> SERVICE_STOPPED, the main thread unblocks and the process terminates. This
> often occurs without both threads running to completion. I think this is a
> race condition caused by the reportServiceStatus() usage. The MSDN
> documentation for SetServiceStatus() states to only call SetServiceStatus()
> with SERVICE_STOPPED after all cleanup has occurred and to only call it once.
> It appears that procrun has a race condition where 2 threads will both
> attempt to report SERVICE_STOPPED and will likely report this while the other
> thread is still running. I believe this is the root cause of why the Service
> Control Manager sometimes is unable to stop the service.
>
> As a potential solution, I modified serviceStop() to not call
> reportServiceStatus(SERVICE_STOPPED...) and to move the SetEvent(
> gShutdownEvent) to the end of the method. This change allows the thread
> running the serviceStop() to complete. Now the only method reporting
> stopped is when serviceMain() exits. With this refactoring to only report
> SERVICE_STOPPED once (per MSDN) the hang has not been reproducible.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)