Skip to content

TcpNetConnection: Read exception - Socket is closed #2974

Closed
@membersound

Description

@membersound

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.

2019-06-24 12:15:25,106 ERROR o.s.i.i.t.c.TcpNetConnection: Read exception my.socket.host:10136:42132:e89e5c73-4987-428e-834d-61a85a739036 SocketException:Socket is closed
2019-06-24 12:16:14,026 ERROR o.s.i.i.t.c.TcpNetConnection: Read exception my.socket.host:10136:42148:07957d9e-9191-49d1-b8ad-96acf85ed6ef SocketException:Socket is closed
2019-06-24 12:16:24,736 ERROR o.s.i.i.t.c.TcpNetConnection: Read exception my.socket.host:10136:42158:53b879c5-289c-478e-b1b5-97a9cbc956fa SocketException:Socket is closed
2019-06-24 12:17:17,207 ERROR o.s.i.i.t.c.TcpNetConnection: Read exception my.socket.host:10136:42202:864c413e-7cac-4fc4-9c0e-79cbc98e8645 SocketException:Socket is closed

This is my simple socket config:

    @Bean
    public AbstractClientConnectionFactory clientFactory() throws Exception {
        TcpConnectionFactoryFactoryBean fact = new TcpConnectionFactoryFactoryBean();
        fact.setType("client");
        fact.setHost(host);
        fact.setPort(port);
        fact.setUsingNio(false);
	fact.setSingleUse(true);
        fact.setDeserializer(new MyDeserializer());
        fact.afterPropertiesSet();
        return (AbstractClientConnectionFactory) fact.getObject();
    }

      static class MyDeserializer implements Deserializer<String> {
		@Override
		public String deserialize(InputStream inputStream) throws IOException {
			try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
				return br.lines().collect(Collectors.joining("\n"));
			}
		}
	}

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?

    @Bean
    @ServiceActivator(inputChannel = "clientChannel")
    public TcpOutboundGateway outboundGateway(AbstractClientConnectionFactory factory) throws Exception {
        TcpOutboundGateway gateway = new TcpOutboundGateway();
        gateway.setConnectionFactory(factory);
        gateway.setRequiresReply(true);
        return gateway;
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions