Results 1 to 10 of 13

Thread: TCP outbound gateway connection pool issue

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    5

    Default TCP outbound gateway connection pool issue

    Hi,

    I'm experiencing an issue with the tcp outbound gateway. This is used to integrate my application with a third party application service running on the same server. The third party respond with an xml for my xml request. Below is the gateway configuration.

    Code:
    	
    
             <int-ip:tcp-connection-factory id="connectionFactory"
    		deserializer="deserializer" host="${socket.host}" port="${socket.port}"
    		pool-size="100" single-use="false"
    		so-keep-alive="true" type="client"
    		so-timeout="20000" />
    
    	<int-ip:tcp-outbound-gateway id="gateway"
    		request-channel="sendStringMessageChannel" reply-channel="recieveStringMessageChannel"
    		connection-factory="connectionFactory" request-timeout="10000"
    		reply-timeout="10000" />
    The deserializer code executed in the reply is as follows. It checks the end tag of the xml response to close the stream and return the response to further processing.

    Code:
    public String deserialize(InputStream inputStream) throws IOException {
    
            BufferedReader br = null;
            StringBuilder sb = null;
            String str = null;
    
            try {
    
                br = new BufferedReader(new InputStreamReader(inputStream));
                sb = new StringBuilder(br.readLine());
    
                while (br.ready()) {
    
                    str = br.readLine();
                    sb.append(str);
                    if (str != null && str.contains("</msg>")) {
    
                        break;
                    }
                }
    
                return sb.toString();
    
            } catch (Exception e) {
    
                throw new RuntimeException(e);
    
            } finally {
                
                if (br != null) {
                    br.close();
                }
            }
        }
    The issue is when put under load and when the limit of the pool is reached it begins to throws following errors.

    Code:
    [ERROR] Failed to send or receive
    org.springframework.integration.MessagingException: Failed to send or receive
    at org.springframework.integration.ip.tcp.TcpOutboundGateway.handleRequestMessage(TcpOutboundGateway.java:120)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    Code:
    2012-10-19 14:20:55.989 TcpOutboundGateway [ERROR] Tcp Gateway exception
    java.net.SocketException: Socket closed
             at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:116)
             at java.net.SocketOutputStream.write(SocketOutputStream.java:132)
    When I check the threads using VisualVM I see this number of threads were created but those never get killed.

    I'm really stuck at this point being unable to tweak it any further to fix the issue. Is there a flow in the configuration? or has any important setting missing or contradictory setting is used?

    SI version is 2.1.0.

    Thanks in advance for any help or insight into issues related to this.

    Sameera

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,147

    Default

    You should not be closing the input stream in the deserializer.

    If you only want to use a socket once for each request, set single-use to "true".

    That said, we should be cleaning up the threads in this case; the pool-size is not really relevant for a client factory with single-use="false".

    I'll open a JIRA ticket.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Mar 2007
    Posts
    5

    Default

    Thanks Gary for quick response. Its late in the night here. I'll update the deserializer code and run the test again. Hope you'll attach the Jira link here.

    Thanks
    Sameera

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,147

    Default

    I have run lots of tests with the deserializer improperly closing the connection and everything gets cleaned up properly; so I won't open a JIRA without more evidence that there is a problem on our end.

    By the way, 2.1.0 is very old. 2.1.4 is the latest release.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Mar 2007
    Posts
    5

    Default

    I did try the suggestions and the upgrade as well. Still the issue seems not solved. I will put more effort to isolate the issue and report back. I had to move on - implemented a class and registered as a service activator to open a socket connection and close after processing - as we had to meet a deadline.

    I'll update this thread if I find a issue with the gateway.

  6. #6
    Join Date
    Nov 2012
    Posts
    13

    Default

    Hi,

    Regarding the previous thread since the outbound gateway should only be used for relatively low-volume use thought of including outbound and inbound channel adapters.But I am getting the exception

    org.springframework.integration.support.channel.Ch annelResolutionException: no output-channel or replyChannel header available.

    Do I have to use header-enricher?

    looking forward for your reply on this.

    Thanks in advance
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •