-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jetty not gracefully shutdown ServletContextListener #6237
Comments
@lorban Can you have a look at this one. |
I can confirm that the problem is reproducible. It seems that registering a This issue is very specific to Jetty 11 as replacing the I'm now investigating why those listeners aren't registered. |
Okay, digging deeper I think I figured the root cause. In the test I wrote to reproduce this issue, I mistakenly placed the It happens that Jetty 10 happily ignores this jar and prefers the parent classloader to load the @scottastanley can you confirm that this is the problem you're having? If that's the case, making sure there is no jar containing I also believe that Jetty 11 should be modified to force loading |
This may already be fixed in #6125 |
It indeed seems to be, thanks for the link. |
I do not include either of these jar files in my war file.
If it helps, I can probably standup a server and try and go back and re-deploy the jetty 10, and maybe jetty 9.4, versions, and assess the behavior. I think I have backups sufficient to let me do this. I only upgraded to jetty 11 in the last few months. |
Why do you have those jetty jars in your |
I have to admit I wondered the same thing when I found those. I run jetty locally for development inside of Eclipse. I suspect I had to add those to my pom to get running locally to work and then forgot to exclude them from the war file. I have already filed a ticket in my project to remove those from the war. Need to check on util as well. Not sure if I even use that directly or not. |
I can't reproduce this problem with jetty-11 with the following settings in server.ini:
We are going to need some more details about your setup and what is happening when you issue the |
Generally the server is idle. I am logged in, but not actively doing anything to trigger server activity. Let me do some looking tonight myself and make sure there is not anything else I missed that might cause this. |
Well, I am hoping this helps. Although I will admit the last observation I have makes the whole thing super confusing for me. Should have never done that last check... With that prelude said, I went through today and came up with a simple case which reproduces this problem. I first observed this problem in my environment in AWS (hence the OS type above), so I cloned my web server and pared the code for my application down so I have a pretty simple case which reproduces this problem. I am attaching two files; example_config.tar.zip : A tar file containing a directory example_config with a runnable example which reproduces this problem. The contents of this directory are as follows;
test-webservice.tar.zip : The source code for the web application. Nothing really here except for the listener and WEB-INF directory and the pom.xml for building. In AWS, when I start then stop jetty, it is calling the listener when the web application is started, but not when it is stopped. This is a log of this process. As above, the listener is called on startup (log line "IN ServiceManagementListener::contextInitialized()") but not called when the WebAppContext is stopped (last line).
Something I observed when trying to simplify the configuration as much as possible was that if I removed the
Maybe there is something with the jaas module triggering this behavior?? |
Okay, now for the weird last observation... When I put the example above together I was trying hard to carve this down to something that could be run locally. In this I was successful. I am able to run and reproduce the same behavior on my Macbook Air where the listener is not called on shutdown. However, when I tried to reproduce the correct behavior where the listener is called on shutdown when the jaas.ini file is not present, it does not work. In this case the listener is still not called on shutdown. I guess this is better than it not failing at all locally... That would have been super frustrating! I am not sure if this datapoint is of any use at all whatsoever. But in case it is, my local environment is this.
I tried the same thing locally with java 11.0.9 and saw the same behavior. |
@scottastanley so your test webapp in your test base works for me :) One major change - I just put in a |
If you turn on the log4j status logging ... [jettyCfg]$ java -Dlog4j.debug=true -jar ../jettyDist/start.jar You'll see the following ...
This shows you that the log4j2 runtime shutdown hook runs before the Jetty graceful runtime shutdown hook. This behavior is documented at https://logging.apache.org/log4j/log4j-2.2/manual/webapp.html |
Let me look in to it a bit more. My original reason for getting concerned on this was that the resources that are released in the listener shutdown logic were not being cleanly released. I noticed on startup I was getting complaints that the resources were not cleanly closed. I actually removed all of that resource shutdown logic when I put this example together. Maybe that original problem was due to some other reason, but not sure what it would have been. Let me add the system log messages outside of log4j and try them in my EC2 node and make sure I am seeing the same behavior. Maybe what I was originally seeing was due to a totally different issue... If this is the case then I am sorry for any wasted time! |
I added the output to System.out and I can confirm that on my EC2 node where I normally deploy the test application does indeed call the contextDestroyed method cleanly. Sorry about the wasted effort on this guys. I appreciate the effort you guys put in to making sure this worked cleanly. I'll look elsewhere for the unclean resource shutdown problem I see. Thought I had it sorted, but I guess not. Closing this bug. |
Jetty version
11.0.2
Java version
java version "13.0.2" 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
OS type/version
Linux ip-172-31-44-100 4.9.85-37.55.amzn1.x86_64 #1 SMP Mon Mar 5 19:00:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Description
I have a web application that is deployed in Jetty 11.0.2. I have a ServletContextListener registered in web.xml,
When jetty starts and my web application is deployed, the
contextInitialized(...)
method is being called, however when I shut down jetty usingkill -s TERM ${JETTY_PID}
thecontextDestroyed(...)
method is not being called.In my server.ini file, I have enabled graceful shutdown with,
When jetty shuts down I am seeing it do the clean shutdown. I see;
The last line being the shutdown of my web app context. However, my listener is never called.
This logic used to work in earlier versions of jetty. I am pretty sure it worked in jetty 9.4, however I unfortunately don't have the log files anymore so I can not see it for certain. May have been an earlier version of jetty when I implemented this to begin with which is the only time I know beyond a doubt it worked.
The text was updated successfully, but these errors were encountered: