Hi Jerome,

Sorry to took so long to reply as I got side tracked with other tasks at hand, but I have tried my test case with the latest Restlet 1.1 RC1 and the same problem still exists. I've attached my test code with simple http server that simply tries to write 80k chars into the response. If the client repeatedly request the page, then eventually bytesWritten on the channel would be 0 (line 248 in ByteUtils.java) and then it'll wait for 10 seconds with line 249
if (SelectorFactory.getSelector().select(10000) == 0) {
Finally an exception will be logged. Interesting though, if you remove the select line and allow it to spin on the channel write, the correct data still gets written to the response. However, that is far from the correct way to implement NIO so I've also tried replacing the select with the following code.

Selector writeSelector = SelectorFactory
                .getSelector();
if (writeSelector == null) {
        // Continue using the main one.
        continue;
}

((SelectableChannel) this.channel).register(
                writeSelector, SelectionKey.OP_WRITE);

if (writeSelector.select(10000) == 0) {
        throw new IOException("Client disconnected");
}

But another set of exceptions occurs after a few requests:

java.io.IOException: An established connection was aborted by the software in your host machine
        at sun.nio.ch.SocketDispatcher.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
        at sun.nio.ch.IOUtil.write(IOUtil.java:75)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
at org.restlet.util.ByteUtils$NbChannelOutputStream.doWrite(ByteUtils.java:243) at org.restlet.util.ByteUtils$NbChannelOutputStream.write(ByteUtils.java:291)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276)
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212)
at org.restlet.resource.StringRepresentation.write(StringRepresentation.java:212) at org.restlet.resource.StreamRepresentation.write(StreamRepresentation.java:68) at com.noelios.restlet.http.HttpServerCall.writeResponseBody(HttpServerCall.java:491) at com.noelios.restlet.http.HttpServerCall.sendResponse(HttpServerCall.java:429) at com.noelios.restlet.http.HttpServerConverter.commit(HttpServerConverter.java:388) at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:148) at com.noelios.restlet.ext.grizzly.HttpParserFilter.execute(HttpParserFilter.java:78) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:169)
Sep 19, 2008 2:29:40 PM com.noelios.restlet.http.HttpServerConverter commit
SEVERE: An exception occured writing the response entity
java.io.IOException: Unable to write to the non-blocking channel. An established connection was aborted by the software in your host machine at org.restlet.util.ByteUtils$NbChannelOutputStream.doWrite(ByteUtils.java:274) at org.restlet.util.ByteUtils$NbChannelOutputStream.write(ByteUtils.java:291)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276)
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212)
at org.restlet.resource.StringRepresentation.write(StringRepresentation.java:212) at org.restlet.resource.StreamRepresentation.write(StreamRepresentation.java:68) at com.noelios.restlet.http.HttpServerCall.writeResponseBody(HttpServerCall.java:491) at com.noelios.restlet.http.HttpServerCall.sendResponse(HttpServerCall.java:429) at com.noelios.restlet.http.HttpServerConverter.commit(HttpServerConverter.java:388) at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:148) at com.noelios.restlet.ext.grizzly.HttpParserFilter.execute(HttpParserFilter.java:78) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:169)
Sep 19, 2008 2:29:40 PM com.noelios.restlet.http.HttpServerConverter commit
WARNING: Unable to send error response
java.io.IOException: An established connection was aborted by the software in your host machine
        at sun.nio.ch.SocketDispatcher.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
        at sun.nio.ch.IOUtil.write(IOUtil.java:75)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
        at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:105)
        at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:73)
at com.noelios.restlet.ext.grizzly.GrizzlyServerCall.writeResponseHead(GrizzlyServerCall.java:269) at com.noelios.restlet.http.HttpServerCall.sendResponse(HttpServerCall.java:416) at com.noelios.restlet.http.HttpServerConverter.commit(HttpServerConverter.java:407) at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:148) at com.noelios.restlet.ext.grizzly.HttpParserFilter.execute(HttpParserFilter.java:78) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:169)


Regards

Jerome Louvel wrote:
Hi Bruce,

There is an existing bug report covering this exception:

"File transfer exception on Linux"
http://restlet.tigris.org/issues/show_bug.cgi?id=502
It would help if you could attach a simple reproducible test case and maybe
dig into Grizzly extension code if you are more adventurous!

Best regards,
Jerome


-----Message d'origine-----
De : news [mailto:[EMAIL PROTECTED] De la part de Bruce Lee
Envoye : mercredi 2 juillet 2008 22:02
A : discuss@restlet.tigris.org
Objet : Random Grizzly IOException

Hi,

I'm testing out grizzly connector with the 1.1M4 built and I noticed that
for
requests takes a bit longer to generate the report, sometimes the following
exceptions occurs:

Jul 2, 2008 4:01:11 PM com.noelios.restlet.http.HttpServerConverter commit
INFO: Exception intercepted
java.io.IOException: Unable to write to the non-blocking channel. Unable to
sele
ct the channel to write to it. Selection timed out.
        at
org.restlet.util.ByteUtils$NbChannelOutputStream.write(ByteUtils.java:219)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
        at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:263)
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:116)
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java:203)
        at java.io.Writer.write(Writer.java:140)
        at
org.restlet.resource.StringRepresentation.write(StringRepresentation.java:19
9)
        at
org.restlet.resource.StreamRepresentation.write(StreamRepresentation.java:59
)
        at
com.noelios.restlet.http.HttpServerCall.writeResponseBody(HttpServerCall.jav
a:545)
        at
com.noelios.restlet.http.HttpServerCall.sendResponse(HttpServerCall.java:484
)
        at
com.noelios.restlet.http.HttpServerConverter.commit(HttpServerConverter.java
:394)
        at
com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:96)
        at
com.noelios.restlet.ext.grizzly.HttpParserFilter.execute(HttpParserFilter.ja
va:68)
        at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolCh
ain.java:124)
        at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:75)
        at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.jav
a:54)
        at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57
)
        at
com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:154)

This happens maybe every few other requests and hence renders the extension
unusable. I'm wondering if this is a known issue with the extension or there
is
something I need to configure to avoid hitting this error.

My environment is as follows:
jdk1.6.0_06
restlet 1.1m4
grizzly 1.7.3 (also tried 1.8.0, the same error)
The output is a XML file converted to String object, stored with
StringRepresentation.

Regards,


import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.data.Request;
import org.restlet.data.Response;

public class Test2 {

        private static Component component = new Component();

        public static void main(String[] args) throws Exception {

                // Create a new Restlet component and add a HTTP server
                // connector to it
                component.getServers().add(Protocol.HTTP);

                // Create a new tracing Restlet
                Restlet restlet = new Restlet() {
                        @Override
                        public void handle(Request request, Response response) {
                                // Print the requested URI path
                                StringBuffer message = new StringBuffer();
                                // setup a response with 80k
                                int size = 80000;
                                char c = 'c';
                                for (int i = 0; i < size; i++) {
                                        message.append(c);
                                }

                                response.setEntity(message.toString(), 
MediaType.TEXT_PLAIN);
                        }
                };

                // Then attach it to the local host
                component.getDefaultHost().attach("/", restlet);

                // Now, let's start the component!
                // Note that the HTTP server connector is also automatically
                // started.
                component.start();

                BufferedReader in = null;
                String line;
                in = new BufferedReader(new InputStreamReader(System.in));
                while (true) {
                        System.out.print("> ");
                        System.out.flush();
                        line = in.readLine();
                        if (line.startsWith("quit") || line.startsWith("exit")) 
{
                                // quits the test client
                                break;
                        }
                }

                component.stop();
        }

}

Reply via email to