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 1d1844c08f7..c43e3fcb953 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,7 @@ * @author Gary Russell * @author John Anderson * @author Artem Bilan + * @author David Herschler Shvo * * @since 2.0 * @@ -139,6 +140,11 @@ private void doClose() { } catch (@SuppressWarnings(UNUSED) Exception e) { } + try { + this.channelOutputStream.close(); + } + catch (@SuppressWarnings(UNUSED) Exception e) { + } super.close(); } @@ -619,12 +625,15 @@ public void write(int b) throws IOException { } @Override - public void close() { - doClose(); - } - - @Override - public void flush() { + public void close() throws IOException { + try { + if (this.selector != null) { + this.selector.close(); + } + } + finally { + super.close(); + } } @Override @@ -663,7 +672,6 @@ protected synchronized void doWrite(ByteBuffer buffer) throws IOException { remaining = buffer.remaining(); } } - } /**