Skip to content

Commit

Permalink
Issue #12272 - Potential deadlock with Vaadin.
Browse files Browse the repository at this point in the history
Added test case.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Nov 8, 2024
1 parent c064dd5 commit 473445b
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@
import org.eclipse.jetty.http2.api.Session;
import org.eclipse.jetty.http2.api.Stream;
import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.frames.DataFrame;
import org.eclipse.jetty.http2.frames.HeadersFrame;
import org.eclipse.jetty.http2.frames.ResetFrame;
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -218,4 +222,69 @@ public void onStartAsync(AsyncEvent event)

assertTrue(errorLatch.await(5, TimeUnit.SECONDS));
}

@Test
public void testSessionShutdownWithPendingRequest() throws Exception
{
CountDownLatch serverFailureLatch = new CountDownLatch(1);
start(new HttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException
{
try
{
request.getInputStream().transferTo(response.getOutputStream());
}
catch (Throwable x)
{
serverFailureLatch.countDown();
throw x;
}
}
});
long idleTimeout = 1000;
connector.setIdleTimeout(idleTimeout);

CountDownLatch clientResetLatch = new CountDownLatch(1);
Session session = client.connect(new InetSocketAddress("localhost", connector.getLocalPort()), new Session.Listener() {})
.get(5, TimeUnit.SECONDS);
MetaData.Request request = new MetaData.Request("POST", HttpURI.from("/"), HttpVersion.HTTP_2, HttpFields.EMPTY);
Stream stream = session.newStream(new HeadersFrame(request, null, false), new Stream.Listener()
{
@Override
public void onDataAvailable(Stream stream)
{
while (true)
{
Stream.Data data = stream.readData();
if (data == null)
{
stream.demand();
return;
}
System.out.println(data);
data.release();
if (data.frame().isEndStream())
return;
}
}

@Override
public void onReset(Stream stream, ResetFrame frame, Callback callback)
{
clientResetLatch.countDown();
}
})
.get(5, TimeUnit.SECONDS);

stream.data(new DataFrame(stream.getId(), UTF_8.encode("Hello Jetty"), false))
.get(5, TimeUnit.SECONDS);
stream.demand();

session.shutdown().join();

assertTrue(serverFailureLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
assertTrue(clientResetLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
}
}

0 comments on commit 473445b

Please sign in to comment.