-
Notifications
You must be signed in to change notification settings - Fork 1.1k
TcpNetConnection: Read exception - Socket is closed #2974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Getting an error log there implies that you have an incomplete reply packet. What is the context in which you are using that factory? I assume an outbound gateway? The default deserializer expects When the socket is closed between messages, the deserializer throws a Getting an ERROR log there means that there is some undecoded data that has been received, hence it's an ERROR condition. I suggest you look at the reply packet(s) in WireShark (or similar) to see exactly what the server is replying with. |
Yes, I'm using a Regardless of what whireshark would show, how could I prevent the error logging? Because all of my communication is working correctly. I always receive the full server response. And as I'm not in control of the socket server, there's not much I could do about the way it responds or terminates the socket. I just need a way to ignore those exceptions (as in my case they are false negative). I mean: my serializer simply reads until |
In future, please don't supply misleading configuration; I can't "guess" you are using a custom deserializer when your configuration showed no deserializer provisioned. As I said, for a normal close, the deserializer should throw a You can add a catch clause to your With the standard deserializers, we can tell if we have actually read any incomplete data when we detect the end of stream. One solution for your implementation would be to enable push back on the input stream. DefaultTcpNetConnectionSupport connectionSupport = new DefaultTcpNetConnectionSupport();
connectionSupport.setPushbackCapable(true); // default push back buffer size is 1
fact.setTcpNetConnectionSupport(connectionSupport); Then static class MyDeserializer implements Deserializer<String> {
@Override
public String deserialize(InputStream inputStream) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
PushbackInputStream pbis = (PushbackInputStream) inputStream;
int first = pbis.read();
if (first < 0) {
throw new SoftEndOfStreamException();
}
pbis.unread(first);
return br.lines().collect(Collectors.joining("\n"));
}
}
} See The TcpNetConnectionSupport Strategy Interface.
|
I will investigate into this. But the root cause is not that the |
Maybe this proofs that the exception is coming from the framework?
|
Interesting - which JVM are you using? I've never seen an exception on But, clearly you're getting an exception there. Update: I just reproduced it in the debugger so there is a race condition that we don't deal with. Will fix. |
Race condition seems to fit my observation that this issue occurs only occasionally. Thank you so far! |
Thanks for your patience. I still think you'll need the pushback trick in your deserializer, even with the fix, because there will still be a (smal) race between the framework getting the inputStream successfully and your |
Fixes spring-projects#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`. Also fix unnecessary `this.` in `MessageHistoryConfigurer.java`. **cherry-pick to 5.0.x, 4.3.x**
Fixes spring-projects#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`.
Fixes #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
Fixes #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`. Also fix unnecessary `this.` in `MessageHistoryConfigurer.java`. **cherry-pick to 5.0.x, 4.3.x** * * Add javadocs to SoftEndOfStreamException
Fixes #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`. Also fix unnecessary `this.` in `MessageHistoryConfigurer.java`. **cherry-pick to 5.0.x, 4.3.x** * * Add javadocs to SoftEndOfStreamException # Conflicts: # spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java
Fixes #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`. Also fix unnecessary `this.` in `MessageHistoryConfigurer.java`. **cherry-pick to 5.0.x, 4.3.x** * * Add javadocs to SoftEndOfStreamException # Conflicts: # spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java # Conflicts: # spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java # spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNetConnectionTests.java
I'm creating a spring-integration client that connects to a server socket. The socket is a singleUse connection.
Problem: the server that I connect to forcibly closes the connection after my client received the server response. Therefore I'm getting lots of errors as follows.
I have to add that those errors do not occur all the time, only occasionally. But still often enough.
This is my simple socket config:
Suggestion: could you add a feature that should NOT log any error if socket is forcibly closed by the remote server? Or could there be a workaround?
The text was updated successfully, but these errors were encountered: