Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-4450

Don't use soTimeout to actively timeout NIO connections

    XMLWordPrintable

    Details

      Description

      Update: Save your time and read my comment first

      I have an application with long-running TCP NIO connections.

      Assume a client silently drops, e.g. because of loss of power. On the server side, the TCP connection will stay open for 15min until "Connection timed out".

      Since this is too long for my use case, I tried setting AbstractConnectionFactory.setSoTimeout(int) to 10s. This value is then used for Socket.setSoTimeout here:

      https://github.com/spring-projects/spring-integration/blob/82e4679495667cb3e2d6889b491b88591c8615df/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java#L161-L163

      The JavaDoc of Socket.setSoTimeout reads:

      [...] With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. [...]

      So that's exactly what I want.

      Next thing that happens is, my client gets dropped every 10s. How so? Well, soTimeout is also used to timeout active connections that haven't sent anything within that time:

      https://github.com/spring-projects/spring-integration/blob/82e4679495667cb3e2d6889b491b88591c8615df/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java#L628-L653

      To my understanding, these are two different cases that should be configured differently. With the current implementation, the only way I see to achieve what I need is to implement a PING-PONG mechanism in both, the client and the server. That seems totally unnecessary though since it's TCP.

      Am I missing something or should this be fixed in spring-integration?

        Attachments

          Activity

            People

            Assignee:
            grussell Gary Russell
            Reporter:
            micheljung Michel Jung
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: