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

PAYARA-3344 Added System Property for Shutdown Grace Period #3702

Merged
merged 4 commits into from Feb 12, 2019

Conversation

Projects
None yet
4 participants
@jbee
Copy link
Contributor

jbee commented Feb 7, 2019

Initially the plan was to use domain.xml based configuration for the grace period setting. I looked into it but it turned out to be overly complicated due to module dependencies and access limitations. So I went for the simpler option using System property fish.payara.shutdowngrace instead. The period is given is milliseconds. E.g. -Dfish.payara.shutdowngrace=1000 for 1 second grace period.

After a first look into where to add the waiting it seamed most appropriate on the outermost level, like the PayaraMicroImpl#shutdown and equivalent methods. After deeper investigation on possible paths during shutdown I found that the common abstraction to server, micro and embedded that is called independent on how the shutdown was initiated should be the GlassFish abstraction. While there are a handful of implementations some of them are wrappers that delegate or extensions that extend. I think there are only 2 relevant implementations: GlassFishImpl and MicroGlassFish. As MicroGlassFish has access to GlassFishImpl it seamed a good way to share the code by making it a static method in GlassFishImpl. Surely no ideal place for common code but I could not find a better place in a common utility class. I believe that this modification includes embedded as embedded seams to wrap one of the other implementations.

In case of thread interruption or illegal value the grace period is zero and the shutdown continues as usual.

While testing the feature for payara micro I got exceptions logged during or after the grade period caused by further calls to stop/dispose as those were not synchronized for micro.

Cjava.lang.IllegalStateException: Already in STOPPING state.
	at fish.payara.micro.boot.runtime.MicroGlassFish.stop(MicroGlassFish.java:80)
	at fish.payara.micro.boot.runtime.MicroGlassFish.dispose(MicroGlassFish.java:96)
	at fish.payara.micro.impl.PayaraMicroImpl.bootStrap(PayaraMicroImpl.java:1045)
	at fish.payara.micro.impl.PayaraMicroImpl.main(PayaraMicroImpl.java:200)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at fish.payara.micro.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
	at fish.payara.micro.boot.loader.Launcher.launch(Launcher.java:107)
	at fish.payara.micro.boot.loader.Launcher.launch(Launcher.java:70)
	at fish.payara.micro.boot.PayaraMicroLauncher.main(PayaraMicroLauncher.java:79)
	at fish.payara.micro.PayaraMicro.main(PayaraMicro.java:397)
java.lang.NullPointerException
	at fish.payara.micro.boot.runtime.MicroGlassFish.stop(MicroGlassFish.java:85)
	at fish.payara.micro.boot.runtime.MicroGlassFish.dispose(MicroGlassFish.java:96)
	at fish.payara.micro.impl.PayaraMicroImpl$1.run(PayaraMicroImpl.java:1600)

Since the GlassFishImpl does synchronize these methods it seams logical that micro should do this as well. I applied it and tested it and it seams to prevent the problem.

As requested I also added a command line option for payara micro: --shutdowngrace <duration-ms>.

@jbee jbee added this to the 5.191 milestone Feb 7, 2019

@jbee jbee self-assigned this Feb 7, 2019

@jbee jbee requested review from smillidge and Pandrex247 Feb 7, 2019

if (status == Status.STOPPED || status == Status.STOPPING || status == Status.DISPOSED) {
throw new IllegalStateException("Already in " + status + " state.");
}


status = Status.STOPPING;

This comment has been minimized.

@jbee

jbee Feb 7, 2019

Author Contributor

Question is: after status is STOPPING will this prevent accepting new requests? I think the intention is to finish the ongoing ones but I guess we do not want to accept new ones.

This comment has been minimized.

@Pandrex247

Pandrex247 Feb 7, 2019

Member

I don't follow what the question is here?
There's a check literally above this that prints an error if multiple things try to stop the server.

This comment has been minimized.

@jbee

jbee Feb 7, 2019

Author Contributor

What I wanted to point out is that before the wait only the status was changed. No internal processing has been signalled to stop by that point. I would imagine that it could very well be the case that new request still are accepted and start to process. If the goal with this feature is to give time to finish started requests it seams only consequent not to accept new ones. I would assume that some parts of the server needs to be stopped or flagged to get this behaviour.

This comment has been minimized.

@smillidge

smillidge Feb 7, 2019

Contributor

Searching the source I don't see that status is used much other than to print it into the admin console. Perhaps we could use this status variable better to stop processing etc.However that would be a different JIRA.

@@ -87,10 +90,24 @@ public synchronized void stop() throws GlassFishException {
throw new IllegalStateException("Already in " + status + " state.");
}
status = Status.STOPPING;

This comment has been minimized.

@jbee

jbee Feb 7, 2019

Author Contributor

Same here: do we prevent accepting new requests effectively?

@jbee

This comment has been minimized.

Copy link
Contributor Author

jbee commented Feb 7, 2019

jenkins test please

@jbee

This comment has been minimized.

Copy link
Contributor Author

jbee commented Feb 7, 2019

jenkins test please

@jbee

This comment has been minimized.

Copy link
Contributor Author

jbee commented Feb 7, 2019

jenkins test please

@jbee

This comment has been minimized.

Copy link
Contributor Author

jbee commented Feb 7, 2019

jenkins test please

Show resolved Hide resolved .../src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java Outdated
if (status == Status.STOPPED || status == Status.STOPPING || status == Status.DISPOSED) {
throw new IllegalStateException("Already in " + status + " state.");
}


status = Status.STOPPING;

This comment has been minimized.

@Pandrex247

Pandrex247 Feb 7, 2019

Member

I don't follow what the question is here?
There's a check literally above this that prints an error if multiple things try to stop the server.

@smillidge
Copy link
Contributor

smillidge left a comment

It would be nice to have a command line flag for Payara Micro that just set this system property

if (status == Status.STOPPED || status == Status.STOPPING || status == Status.DISPOSED) {
throw new IllegalStateException("Already in " + status + " state.");
}


status = Status.STOPPING;

This comment has been minimized.

@smillidge

smillidge Feb 7, 2019

Contributor

Searching the source I don't see that status is used much other than to print it into the admin console. Perhaps we could use this status variable better to stop processing etc.However that would be a different JIRA.

@jbee

This comment has been minimized.

Copy link
Contributor Author

jbee commented Feb 8, 2019

It would be nice to have a command line flag for Payara Micro that just set this system property

I'll add one.

@jbee

This comment has been minimized.

Copy link
Contributor Author

jbee commented Feb 8, 2019

jenkins test please

@Pandrex247 Pandrex247 merged commit 4195298 into payara:master Feb 12, 2019

59 checks passed

Payara Quick Build and Test Quick build and test passed!
Details
security/snyk - api/payara-api/pom.xml (payara-ci) No new issues
Details
security/snyk - api/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/admin/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/admingui/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/ant-tasks/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/appclient/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/batch/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/common/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/concurrent/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/connectors/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/core/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/deployment/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/distributions/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/ejb/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/extras/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/featuresets/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/flashlight/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/grizzly/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/ha/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/installer/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/javaee-api/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/jdbc/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/jms/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/load-balancer/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/orb/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/osgi-platforms/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/packager/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/payara-appserver-modules/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/persistence/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/registration/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/resources/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/security/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/tests/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/transaction/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/web/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/webservices/pom.xml (payara-ci) No new issues
Details
security/snyk - copyright/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/admin/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/cluster/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/common/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/core/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/deployment/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/diagnostics/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/distributions/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/flashlight/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/grizzly/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/hk2/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/osgi-platforms/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/packager/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/payara-modules/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/resources-l10n/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/resources/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/security/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/test-utils/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/tests/pom.xml (payara-ci) No new issues
Details
security/snyk - pom.xml (payara-ci) No new issues
Details

@arjantijms arjantijms requested a review from MeroRai Feb 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.