You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Daniel F. Savarese" <df...@savarese.org> on 2008/09/05 20:43:22 UTC

Re: The java.net.SocketException: No buffer space available (maximum connections reached?): listen failed Exception

[I'm replying from the time-delayed digest, so I apologize in advance
 if someone has already answered this.]

In message <19...@talk.nabble.com>, chitraa writes:
>Without the custom SocketFactory, the connection seems to hang (Hence the
>reason for customising the SocketFactory to set a timeout value). I could
>not replicate the No buffer space available exception.

What's  probably happening is that the connection is timing out, but
the socket isn't being closed.  For example, in your factory method
you have:
  socket.bind(localaddr);
  socket.connect(remoteaddr, clientTimeout);
  return socket;
If the connect times out and throws an exception, the socket should still
be bound.  Therefore, as the application continues to run, it gradually
consumes more and more file descriptors until it runs out.  Try changing
the contents of your factory method to:
  Socket socket = Socket();
  try {
    ...
  } catch(IOException ioe) {
    socket.close();
    throw ioe;
  }
  return socket;

Presumably, you already know whether or not the connections have
been timing out because you must have an exception handler in your main
application code (else the program would abort assuming your main
is declared as throwing IOException).

daniel

o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o o-o-o-o-o-o-o-o-o-o-o-o-o-o
                    Igfip                      o    s a v a r e s e
The strategic alternative for online games(tm).o   software research
            http://www.igfip.com/              o http://www.savarese.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: The java.net.SocketException: No buffer space available (maximum connections reached?): listen failed Exception

Posted by chitraa <ac...@gmail.com>.
I don't seem to be getting this error anymore. From what I can gather (for
the reference of others who have/are currently encountering this problem),
there were two reasons why the 'No buffer space available' exception was
being thrown:

1. As explained by Daniel in his post, if an exception occurs while a binded
socket tries to make a connection to a machine, the socket does not get
unbounded and closed. Try adding a java try catch block to ensure all
sockets get unbounded and closed if an exception is thrown while either i)
trying to establish a connection to the machine or ii) performing file
transfer.

2. A memory or file handle leak can also be the source of the problem. When
a program opens up too many handles rapidly, it exhausts the system
resources - hence throwing the "No Buffer Space" error. In my case, I found
that an external application was opening up too many handles. When I closed
that process, the error did not appear. To check and see how many handles
the processes on your computer has opened up, look at your Task Manager and
click View -> Select Columns -> Handle Count.

Thanks to everyone who took the time to reply to this post and give me
valuable suggestions. :)

Regards,
Chitra 
-- 
View this message in context: http://www.nabble.com/The-java.net.SocketException%3A-No-buffer-space-available-%28maximum-connections-reached-%29%3A-listen-failed-Exception-tp19269806p19602683.html
Sent from the Commons - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: The java.net.SocketException: No buffer space available (maximum connections reached?): listen failed Exception

Posted by Chitraleka Appalanaidu <ac...@gmail.com>.
Hi Daniel,

What you said makes sense. I will add a catch clause to close the socket if
there is an exception. Will post the outcome here.

Thank you.


On Sat, Sep 6, 2008 at 4:43 AM, Daniel F. Savarese <df...@savarese.org> wrote:

>
> [I'm replying from the time-delayed digest, so I apologize in advance
>  if someone has already answered this.]
>
> In message <19...@talk.nabble.com>, chitraa writes:
> >Without the custom SocketFactory, the connection seems to hang (Hence the
> >reason for customising the SocketFactory to set a timeout value). I could
> >not replicate the No buffer space available exception.
>
> What's  probably happening is that the connection is timing out, but
> the socket isn't being closed.  For example, in your factory method
> you have:
>   socket.bind(localaddr);
>  socket.connect(remoteaddr, clientTimeout);
>  return socket;
> If the connect times out and throws an exception, the socket should still
> be bound.  Therefore, as the application continues to run, it gradually
> consumes more and more file descriptors until it runs out.  Try changing
> the contents of your factory method to:
>  Socket socket = Socket();
>  try {
>    ...
>  } catch(IOException ioe) {
>    socket.close();
>    throw ioe;
>  }
>  return socket;
>
> Presumably, you already know whether or not the connections have
> been timing out because you must have an exception handler in your main
> application code (else the program would abort assuming your main
> is declared as throwing IOException).
>
> daniel
>
> o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o o-o-o-o-o-o-o-o-o-o-o-o-o-o
>                    Igfip                      o    s a v a r e s e
> The strategic alternative for online games(tm).o   software research
>            http://www.igfip.com/              o http://www.savarese.com/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>