Skip to content
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

Network breakdown cause a file descriptor leak #3

Closed
shark300 opened this issue Sep 30, 2015 · 2 comments
Closed

Network breakdown cause a file descriptor leak #3

shark300 opened this issue Sep 30, 2015 · 2 comments
Assignees
Labels

Comments

@shark300
Copy link

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)
@shark300
Copy link
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;
    }
  }

@shark300
Copy link
Author

shark300 commented Oct 1, 2015

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;
    }
  }

@brainslog brainslog self-assigned this Mar 28, 2017
@brainslog brainslog added the bug label Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants