Hi Thierry, FYI: We've tested this solution using a custom WritableRepresentation subclass for a couple of weeks now. We haven't seen this issue anymore since then.
Regards, Arjohn On 16/05/2012 16:47, Thierry Boileau wrote: > Hello Arjohn, > > sorry for the delay, I ask Jérôme to take a closer look at your suggestion. > > Best regards, > Thierry Boileau > > Hi all, me again :-) > > I have debugged this issue further and have probably found a simple fix. > I've migrated from 2.0.x to 2.1.x in the mean time and both version are > affected by this issue. > > The "Unable to establish loopback connection" problem surfaces when > using resources that return WritableRepresentation objects. In the stack > trace below, ChannelRepresentation.write(OutputStream) converts the > writable channel to a readable one through > WritableRepresentation.getChannel() and > NioUtils.getReadableByteChannel(...). This last method uses a > java.nio.channels.Pipe as a buffer between the writer and reader. > Because this pipe isn't closed/released in time, the system will run out > of available ports under high load, resulting in the shown stack trace. > > Making sure that the reader-side of the pipe is always closed could help > to resolve this issue, but there's a more elegant solution that doesn't > use ports. This solution is to override write(OutputStream) in > WritableRepresentation, wrap the OutputStream in a WritableByteChannel > using e.g. java.nio.channels.Channels.newChannel(...) and pass that to > WritableRepresentation.write(WritableByteChannel). Gut feeling is that > this might even improve the performance as it feels like a lighter > weight approach than using the system's pipes. > > WDYT? Can we get this fix? > > Cheers, > > Arjohn > > > > On 20/04/2012 10:01, Arjohn Kampman wrote: > > Hi all, > > > > My restlet server is running into the error mentioned in the subject > > after a couple of minutes of moderate load. After this error, the > server > > stops responding. Does anyone know what causes this error and how > it can > > be fixed? > > > > The full stack trace looks like this: > > > > org.restlet.engine.http.adapter.ServerAdapter commit > > SEVERE: An exception occured writing the response entity > > java.io.IOException: Unable to establish loopback connection > > at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:106) > > at java.security.AccessController.doPrivileged(Native Method) > > at sun.nio.ch.PipeImpl.<init>(PipeImpl.java:122) > > at > sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:27) > > at java.nio.channels.Pipe.open(Pipe.java:133) > > at org.restlet.engine.io.NioUtils.getChannel(NioUtils.java:160) > > at > > > > org.restlet.representation.WritableRepresentation.getChannel(WritableRepresentation.java:65) > > at > > > > org.restlet.representation.ChannelRepresentation.write(ChannelRepresentation.java:71) > > at > > > > org.restlet.engine.application.EncodeRepresentation.write(EncodeRepresentation.java:304) > > at > > > org.restlet.engine.http.ServerCall.writeResponseBody(ServerCall.java:550) > > at > org.restlet.engine.http.ServerCall.sendResponse(ServerCall.java:488) > > at > > > org.restlet.ext.jetty.internal.JettyCall.sendResponse(JettyCall.java:327) > > at > > > > org.restlet.engine.http.adapter.ServerAdapter.commit(ServerAdapter.java:197) > > at > > > org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java:151) > > at > > > > org.restlet.ext.jetty.JettyServerHelper$WrappedServer.handle(JettyServerHelper.java:167) > > at > > > > org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:594) > > at > > > > org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1042) > > at > org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:549) > > at > org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:211) > > at > org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:424) > > at > > > > org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:506) > > at > > > > org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436) > > at java.lang.Thread.run(Thread.java:662) > > Caused by: java.net.SocketException: No buffer space available > (maximum > > connections reached?): connect > > at sun.nio.ch.Net.connect(Native Method) > > at > sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:500) > > at java.nio.channels.SocketChannel.open(SocketChannel.java:146) > > at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:78) > > > > > > Any help would be highly appreciated. Thanks in advance! > > > > -- > Arjohn Kampman - www.aduna-software.com <http://www.aduna-software.com> > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2952569 > > <http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2952569> > > -- Arjohn Kampman - www.aduna-software.com ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2963894