From c5c4425a0bab5439348709e6dc15e0e0d8aac56a Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 7 Mar 2012 14:04:27 +0100 Subject: [PATCH] Ignoring data frames after RST_STREAM. --- .../eclipse/jetty/spdy/StandardSession.java | 50 +++---- .../eclipse/jetty/spdy/ResetStreamTest.java | 123 ++++++++++++++++++ 2 files changed, 150 insertions(+), 23 deletions(-) create mode 100644 jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ResetStreamTest.java diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java index 2631c656f97..a3db9e860cd 100644 --- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java +++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java @@ -135,7 +135,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler handler) + public void syn(SynInfo synInfo, StreamFrameListener listener, long timeout, TimeUnit unit, Handler handler) { // Synchronization is necessary. // SPEC v3, 2.3.1 requires that the stream creation be monotonically crescent @@ -154,7 +154,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler handler) + public void ping(long timeout, TimeUnit unit, Handler handler) { int pingId = pingIds.getAndAdd(2); PingInfo pingInfo = new PingInfo(pingId); @@ -330,7 +334,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler void control(IStream stream, ControlFrame frame, long timeout, TimeUnit unit, final Handler handler, C context) + public void control(IStream stream, ControlFrame frame, long timeout, TimeUnit unit, Handler handler, C context) { try { @@ -732,7 +736,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler handler, FrameBytes frameBytes) + protected void write(ByteBuffer buffer, Handler handler, FrameBytes frameBytes) { if (controller != null) controller.write(buffer, handler, frameBytes); @@ -937,7 +941,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler serverSessionRef = new AtomicReference<>(); + final CountDownLatch synLatch = new CountDownLatch(1); + final CountDownLatch rstLatch = new CountDownLatch(1); + Session clientSession = startClient(startServer(new ServerSessionFrameListener.Adapter() + { + @Override + public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) + { + Session serverSession = stream.getSession(); + serverSessionRef.set(serverSession); + serverSession.rst(new RstInfo(stream.getId(), StreamStatus.REFUSED_STREAM)); + synLatch.countDown(); + return null; + } + }), new SessionFrameListener.Adapter() + { + @Override + public void onRst(Session session, RstInfo rstInfo) + { + rstLatch.countDown(); + } + }); + + clientSession.syn(new SynInfo(false), null).get(5, TimeUnit.SECONDS); + + Assert.assertTrue(synLatch.await(5, TimeUnit.SECONDS)); + Session serverSession = serverSessionRef.get(); + Assert.assertEquals(0, serverSession.getStreams().size()); + + Assert.assertTrue(rstLatch.await(5, TimeUnit.SECONDS)); + Assert.assertEquals(0, clientSession.getStreams().size()); + } + + @Test + public void testRefusedStreamIgnoresData() throws Exception + { + final CountDownLatch synLatch = new CountDownLatch(1); + final CountDownLatch dataLatch = new CountDownLatch(1); + final CountDownLatch rstLatch = new CountDownLatch(1); + Session session = startClient(startServer(new ServerSessionFrameListener.Adapter() + { + @Override + public StreamFrameListener onSyn(Stream stream, SynInfo synInfo) + { + try + { + // Refuse the stream, we must ignore data frames + Assert.assertTrue(synLatch.await(5, TimeUnit.SECONDS)); + stream.getSession().rst(new RstInfo(stream.getId(), StreamStatus.REFUSED_STREAM)); + return new StreamFrameListener.Adapter() + { + @Override + public void onData(Stream stream, DataInfo dataInfo) + { + dataLatch.countDown(); + } + }; + } + catch (InterruptedException x) + { + x.printStackTrace(); + return null; + } + } + }), new SessionFrameListener.Adapter() + { + @Override + public void onRst(Session session, RstInfo rstInfo) + { + rstLatch.countDown(); + } + }); + + Stream stream = session.syn(new SynInfo(false), null).get(5, TimeUnit.SECONDS); + stream.data(new StringDataInfo("data", true), 5, TimeUnit.SECONDS, new Handler.Adapter() + { + @Override + public void completed(Void context) + { + synLatch.countDown(); + } + }); + + Assert.assertTrue(rstLatch.await(5, TimeUnit.SECONDS)); + Assert.assertFalse(dataLatch.await(1, TimeUnit.SECONDS)); + } +}