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

Improve cleanup of deflater/inflater pools for PerMessageDeflateExtension #8134

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,20 +13,23 @@

package org.eclipse.jetty.websocket.core;

import java.io.Closeable;
import java.io.IOException;

/**
* Interface for WebSocket Extensions.
* <p>
* That {@link Frame}s are passed through the Extension via the {@link IncomingFrames} and {@link OutgoingFrames} interfaces
*/
public interface Extension extends IncomingFrames, OutgoingFrames
public interface Extension extends IncomingFrames, OutgoingFrames, Closeable
{

void init(ExtensionConfig config, WebSocketComponents components);

/**
* Used to clean up any resources after connection close.
*/
default void close()
default void close() throws IOException
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
{
}

Expand Down
Expand Up @@ -62,9 +62,17 @@ public ExtensionStack(WebSocketComponents components, Behavior behavior)

public void close()
{
for (Extension e : extensions)
for (Extension ext : extensions)
{
e.close();
try
{
ext.close();
}
catch (Throwable t)
{
if (LOG.isDebugEnabled())
LOG.debug("Extension Error During Close", t);
}
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Expand Up @@ -184,6 +184,7 @@ public void onClose(Throwable cause)
{
try (AutoLock l = lock.lock())
{
// TODO: find a way to not create exception if cause is null.
closedCause = cause == null ? new ClosedChannelException()
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
{
@Override
Expand Down
Expand Up @@ -151,7 +151,14 @@ public void init(final ExtensionConfig config, WebSocketComponents components)
public void close()
{
// TODO: use IteratingCallback.close() instead of creating exception with failFlusher methods.
ClosedChannelException exception = new ClosedChannelException();
ClosedChannelException exception = new ClosedChannelException()
{
@Override
public Throwable fillInStackTrace()
{
return this;
}
};
incomingFlusher.failFlusher(exception);
outgoingFlusher.failFlusher(exception);
releaseInflater();
Expand Down
Expand Up @@ -83,6 +83,7 @@ public final void sendFrame(Frame frame, Callback callback, boolean batch)
*/
public void failFlusher(Throwable t)
{
// TODO: find a way to close the flusher in non error case without exception.
boolean failed = false;
try (AutoLock l = lock.lock())
{
Expand All @@ -91,6 +92,10 @@ public void failFlusher(Throwable t)
failure = t;
failed = true;
}
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
else
{
failure.addSuppressed(t);
}
}

if (failed)
Expand Down