From 50ead5c19cadb20e5ee65635b31548ecd6736e80 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 28 Feb 2012 17:01:30 +0100 Subject: [PATCH] Synchronized the generation and enqueuing of control frames, in order to maintain a correct compression context. --- .../eclipse/jetty/spdy/StandardSession.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java b/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java index 4ea0050e598..b2072bf0f75 100644 --- a/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java +++ b/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java @@ -717,12 +717,20 @@ public class StandardSession implements ISession, Parser.Listener, Handler frameBytes = new ControlFrameBytes<>(frame, buffer, handler, context); - if (timeout > 0) - frameBytes.task = scheduler.schedule(frameBytes, timeout, unit); - enqueueLast(frameBytes); + + // Synchronization is necessary, since we may have concurrent replies + // and those needs to be generated and enqueued atomically in order + // to maintain a correct compression context + synchronized (this) + { + ByteBuffer buffer = generator.control(frame); + logger.debug("Queuing {} on {}", frame, stream); + ControlFrameBytes frameBytes = new ControlFrameBytes<>(frame, buffer, handler, context); + if (timeout > 0) + frameBytes.task = scheduler.schedule(frameBytes, timeout, unit); + enqueueLast(frameBytes); + } + flush(); }