diff --git a/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java b/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java
index e5db2519ad2df84bc31a03c30e052e5c6c051810..a656c94587b84f0296cbde6487e52c04cae0ba70 100644
--- a/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java
+++ b/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java
@@ -106,11 +106,11 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 			// Write packets until interrupted
 			try {
 				while(!interrupted) {
+					// Flush the stream if it's going to be idle
+					if(writerTasks.isEmpty()) out.flush();
 					ThrowingRunnable<IOException> task = writerTasks.take();
 					if(task == CLOSE) break;
 					task.run();
-					// Flush the stream if it's going to be idle
-					if(writerTasks.isEmpty()) out.flush();
 				}
 				out.flush();
 			} catch(InterruptedException e) {