Skip to content

Network breakdown cause a file descriptor leak #3

Description

@shark300

Hi,

I found a file descriptor leak after a network breakdown. The root cause is socketChannel.connect(destAddress) in TCPTransportClient.java. I got this exception on Red Hat Enterprise Linux Server release 7.1 (Maipo) during breakdown:

org.jdiameter.client.api.io.TransportException: Cannot init transport:
        at org.jdiameter.client.impl.transport.tcp.TCPClientConnection.connect(TCPClientConnection.java:111)
        at org.jdiameter.client.impl.controller.PeerImpl$ActionContext.connect(PeerImpl.java:685)
        at org.jdiameter.server.impl.fsm.PeerFSMImpl$4.processEvent(PeerFSMImpl.java:378)
        at org.jdiameter.client.impl.fsm.PeerFSMImpl$3.run(PeerFSMImpl.java:207)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused
        at sun.nio.ch.Net.connect0(Native Method)
        at sun.nio.ch.Net.connect(Net.java:454)
        at sun.nio.ch.Net.connect(Net.java:446)
        at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
        at org.jdiameter.client.impl.transport.tcp.TCPTransportClient.initialize(TCPTransportClient.java:131)
        at org.jdiameter.client.impl.transport.tcp.TCPClientConnection.connect(TCPClientConnection.java:107)

Activity

  1. shark300 commented on Sep 30, 2015

    @shark300
    Author

    I used this code to prevent the problem:

      public void initialize() throws IOException, NotInitializedException {
        logger.debug("Initialising TCPTransportClient. Origin address is [{}] and destination address is [{}]", origAddress, destAddress);
        if (destAddress == null) {
          throw new NotInitializedException("Destination address is not set");
        }
        socketChannel = SelectorProvider.provider().openSocketChannel();
    
        if (origAddress != null) {
          socketChannel.socket().bind(origAddress);
        }
    
        try {
          socketChannel.connect(destAddress);
          //PCB added logging
          socketChannel.configureBlocking(BLOCKING_IO);
          getParent().onConnected();
        } catch (ConnectException e) {
          if (origAddress != null) {
            socketChannel.socket().close();
          }
          socketChannel.close();
          throw e;
        }
      }
  2. shark300 commented on Oct 1, 2015

    @shark300
    Author

    I impoved my code because I got this exception sometimes whitch cause FDL again:

    org.jdiameter.client.api.io.TransportException: Cannot init transport:
            at org.jdiameter.client.impl.transport.tcp.TCPClientConnection.connect(TCPClientConnection.java:111)
            at org.jdiameter.client.impl.controller.PeerImpl$ActionContext.connect(PeerImpl.java:685)
            at org.jdiameter.server.impl.fsm.PeerFSMImpl$4.processEvent(PeerFSMImpl.java:378)
            at org.jdiameter.client.impl.fsm.PeerFSMImpl$3.run(PeerFSMImpl.java:207)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.net.BindException: Address already in use
            at sun.nio.ch.Net.bind0(Native Method)
            at sun.nio.ch.Net.bind(Net.java:433)
            at sun.nio.ch.Net.bind(Net.java:425)
            at sun.nio.ch.SocketChannelImpl.bind(SocketChannelImpl.java:585)
            at sun.nio.ch.SocketAdaptor.bind(SocketAdaptor.java:135)
            at org.jdiameter.client.impl.transport.tcp.TCPTransportClient.initialize(TCPTransportClient.java:131)
            at org.jdiameter.client.impl.transport.tcp.TCPClientConnection.connect(TCPClientConnection.java:107)
    
      public void initialize() throws IOException, NotInitializedException {
        logger.debug("Initialising TCPTransportClient. Origin address is [{}] and destination address is [{}]", origAddress, destAddress);
        if (destAddress == null) {
          throw new NotInitializedException("Destination address is not set");
        }
        socketChannel = SelectorProvider.provider().openSocketChannel();
    
        try {
          if (origAddress != null) {
            socketChannel.socket().bind(origAddress);
          }
    
          socketChannel.connect(destAddress);
          //PCB added logging
          socketChannel.configureBlocking(BLOCKING_IO);
          getParent().onConnected();
        } catch (IOException e) {
          if (origAddress != null) {
            socketChannel.socket().close();
          }
          socketChannel.close();
          throw e;
        }
      }
  3. self-assigned this
    on Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions