GH-2974: Fix race in TcpNetConnection.getPayload()

Fixes https://github.com/spring-projects/spring-integration/issues/2974

There is a race in that we could get a `SocketException` in `inputStream`.
Since this is between payloads, it needs to be thrown as a
`SoftEndOfStreamException`.

* * Add javadocs to SoftEndOfStreamException

* * SEOSE is now a RuntimeException (can't be an UncheckedIOException - no default CTOR
This commit is contained in:
Gary Russell
2019-06-26 11:15:34 -04:00
committed by Artem Bilan
parent 59cdc4ddae
commit 175223d0e0
6 changed files with 69 additions and 7 deletions

View File

@@ -125,9 +125,16 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling
@Override
public Object getPayload() {
InputStream inputStream;
try {
inputStream = inputStream();
}
catch (IOException e1) {
throw new SoftEndOfStreamException("Socket closed when getting input stream", e1);
}
try {
return getDeserializer()
.deserialize(inputStream());
.deserialize(inputStream);
}
catch (IOException e) {
throw new UncheckedIOException(e);
@@ -291,6 +298,7 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling
* @since 5.2
* @see Socket#shutdownInput()
*/
@Override
public void shutdownInput() throws IOException {
this.socket.shutdownInput();
}
@@ -301,6 +309,7 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling
* @since 5.2
* @see Socket#shutdownOutput()
*/
@Override
public void shutdownOutput() throws IOException {
this.socket.shutdownOutput();
}

View File

@@ -16,8 +16,6 @@
package org.springframework.integration.ip.tcp.serializer;
import java.io.IOException;
/**
* Used to communicate that a stream has closed, but between logical
* messages.
@@ -26,16 +24,33 @@ import java.io.IOException;
* @since 2.0
*
*/
public class SoftEndOfStreamException extends IOException {
public class SoftEndOfStreamException extends RuntimeException {
private static final long serialVersionUID = 7309907445617226978L;
private static final long serialVersionUID = -2209857413498073058L;
/**
* Default constructor.
*/
public SoftEndOfStreamException() {
super();
}
/**
* Construct an instance with the message.
* @param message the message.
*/
public SoftEndOfStreamException(String message) {
super(message);
}
/**
* Construct an instance with the message and cause.
* @param message the message.
* @param cause the cause.
* @since 4.3.21.
*/
public SoftEndOfStreamException(String message, Throwable cause) {
super(message, cause);
}
}