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

Fix #5835 Durable Filters, Servlets and Listeners #5837

Closed
wants to merge 10 commits into from

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Dec 22, 2020

#5835 Filters, Servlets and Listeners are only durable if added prior to starting.

Filters, Servlets and Listeners are only durable if added prior to starting.
@gregw gregw requested a review from janbartel December 22, 2020 13:38
For non durable ServletContextListeners ensure that initialized is called if they are added during starting and that destroyed is called.
Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

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

Can we improve the apidoc and/or the server dump on this?

@@ -689,7 +689,7 @@ public void addEventListener(EventListener listener)
{
_eventListeners.add(listener);

if (!(isStarted() || isStarting()))
if (!isRunning())
{
_durableListeners.add(listener);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this _durableListeners dumped during server dump?
Either as the collection it is, or by decorating the normal listener collection with something indicating that it is a durable listener?
Seems like that would have been useful for debug of behaviors, especially considering that !isRunning() above is a subtle behavior that isn't documented in the apidoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be good info to dump, but not easy to do without making things very verbose (ie repeating the listeners) as when dumping a listener it doesn't know if it is durable or not.

@gregw
Copy link
Contributor Author

gregw commented Dec 22, 2020

@lachlan-roberts can you look at the failing tests in this one, as it is the stop/start websocket test that this PR is meant to help with.

lachlan-roberts and others added 2 commits December 23, 2020 18:49
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Update WebSocketUpgradeFilter to have durable configuration.
@gregw gregw requested a review from joakime December 23, 2020 17:26
@gregw
Copy link
Contributor Author

gregw commented Dec 23, 2020

@janbartel this is ready for review now

@gregw gregw removed the request for review from lachlan-roberts December 23, 2020 17:27
@@ -131,12 +132,12 @@ public static WebSocketUpgradeFilter configureContext(ServletContext context) th

private NativeWebSocketConfiguration configuration;
private String instanceKey;
private boolean localConfiguration = false;
private boolean durableConfiguration = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

The no-args constructor could call this((NativeWebSocketConfiguration)null) and then this could be final.

@@ -146,6 +147,7 @@ public WebSocketUpgradeFilter(WebSocketServerFactory factory)

public WebSocketUpgradeFilter(NativeWebSocketConfiguration configuration)
{
durableConfiguration = configuration != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is something strange about this.

There is currently no code which creates a WebSocketUpgradeFilter without a configuration except when the filter is added with the class.

context.addFilter(WebSocketUpgradeFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

Even when we have a non-durable filter we use a durable configuration, which turns out it doesn't matter as the filter is not reused.

So now we can have:

  1. durable filter with durable configuration
  2. durable filter with non-durable configuration
  3. non-durable filter with durable configuration
  4. non-durable filter with non-durable configuration

Do we really need all these cases, can't we work out if the filter is durable and make the configuration the same. Maybe we could do something like:

@Override
public void init(FilterConfig config) throws ServletException
{
    ServletContextHandler servletContextHandler = ServletContextHandler.getServletContextHandler(config.getServletContext());
    ServletHandler servletHandler = servletContextHandler.getServletHandler();
    durableConfiguration = servletHandler.isDurable(this);
    ...

Copy link
Contributor

@janbartel janbartel left a comment

Choose a reason for hiding this comment

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

I would strongly prefer it if we threw IllegalStateException when adding an SCL after the context has already been fully started.

@@ -702,7 +702,16 @@ public void addEventListener(EventListener listener)
}

if (listener instanceof ServletContextListener)
_servletContextListeners.add((ServletContextListener)listener);
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should throw IllegalStateException here: you should not be able to add a ServletContextListener after the context has initialized, as this is contrary to the Servlet Spec. I know this is a jetty api, however if you're using a SCL, you're using the spec.

Furthermore, the ServletContextListener is supposed to be called before any servlets, filters etc have been initialized, whereas this change allows a ServletContextListener to be called at any old time maybe even in a shutdown sequence - who knows what could happen.

I also do not think it's a good idea to do the listener initialization in multiple places: having it in 1 place makes the (already very complicated) initialization sequence very clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will try with ISE and see if we break anything....

@gregw gregw marked this pull request as draft February 10, 2021 07:44
@joakime
Copy link
Contributor

joakime commented Feb 11, 2021

This PR has test failures

java.lang.IllegalStateException: Context is initialized
	at org.eclipse.jetty.server.handler.ContextHandlerTest.testNonDurableContextListener(ContextHandlerTest.java:524)

@gregw
Copy link
Contributor Author

gregw commented Mar 2, 2021

This needs to be rebased onto Jetty-10

@gregw
Copy link
Contributor Author

gregw commented Mar 8, 2021

replaced by #6027

@gregw gregw closed this Mar 8, 2021
@joakime joakime deleted the jetty-9.4.x-5835-durable branch April 16, 2021 14:35
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.

None yet

4 participants