From 9b626c946b5937ee05d0ef20bd16411b386c4625 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Sat, 11 Jun 2011 10:35:12 -0400 Subject: [PATCH] INT-1937 Fix NIO Connection State on Exception --- .../ip/tcp/connection/TcpNioConnection.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index fd7b53ac5e..ab72f628b4 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -258,25 +258,27 @@ public class TcpNioConnection extends AbstractTcpConnection { } this.writingToPipe = true; - if (this.taskExecutor == null) { - this.taskExecutor = Executors.newSingleThreadExecutor(); - } - // If there is no assembler running, start one - checkForAssembler(); - this.rawBuffer.clear(); - int len = this.socketChannel.read(this.rawBuffer); - if (len < 0) { + try { + if (this.taskExecutor == null) { + this.taskExecutor = Executors.newSingleThreadExecutor(); + } + // If there is no assembler running, start one + checkForAssembler(); + this.rawBuffer.clear(); + int len = this.socketChannel.read(this.rawBuffer); + if (len < 0) { + this.writingToPipe = false; + this.closeConnection(); + } + this.rawBuffer.flip(); + if (logger.isDebugEnabled()) { + logger.debug("Read " + rawBuffer.limit() + " into raw buffer"); + } + this.pipedOutputStream.write(this.rawBuffer.array(), 0, this.rawBuffer.limit()); + this.pipedOutputStream.flush(); + } finally { this.writingToPipe = false; - this.closeConnection(); } - this.rawBuffer.flip(); - if (logger.isDebugEnabled()) { - logger.debug("Read " + rawBuffer.limit() + " into raw buffer"); - } - this.pipedOutputStream.write(this.rawBuffer.array(), 0, this.rawBuffer.limit()); - this.pipedOutputStream.flush(); - this.writingToPipe = false; - } private void checkForAssembler() {