StreamSinkChannel - repeatable writes error
by Matej Lazar
Hi, I'm writing an http server for Ceylon on top of undertow.
All bytes are written to response and successfully transferred, but exception bellow occurs when shutdownWrites is called.
Stepping through a "write" method of FixedLengthStreamSinkChannel, looks like "state" is not updated correctly, it is always subtracted only for are number of bytes written in one loop.
Am I missing something or is it a bug ?
byte array size is 6919638, usually there are 147456 bytes written to a response in a loop
My code for writing bytes to response ... not quite Java, but readable ;)
shared actual void writeBytes(Array<Integer> bytes) {
//ByteBuffer.wrap
value bb = wrapByteBuffer(bytes);
value response = getResponse();
variable Integer remaining := bytes.size;
while (remaining > 0) {
variable Integer written := 0;
while((written := response.write(bb)) > 0) {
remaining -= written;
try {
response.awaitWritable();
} catch(JIOException e) {
//TODO
print(e);
}
}
}
}
Exception in thread "XNIO-1 task-2" java.lang.Error: org.xnio.channels.FixedLengthUnderflowException: 6815744 bytes remaining
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1116)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.xnio.channels.FixedLengthUnderflowException: 6815744 bytes remaining
at org.xnio.channels.FixedLengthStreamSinkChannel.shutdownWrites(FixedLengthStreamSinkChannel.java:291)
at ceylon.net.httpd.internal.HttpResponseImpl.responseDone(HttpResponseImpl.ceylon:71)
at ceylon.net.httpd.internal.CeylonRequestHandler$AsyncInvoker$1completionHandler_.handleComplete(CeylonRequestHandler.ceylon:56)
at ceylon.net.httpd.endpoints.StaticFileEndpoint.service(StaticFileEndpoint.ceylon:50)
at ceylon.net.httpd.internal.CeylonRequestHandler$AsyncInvoker.run(CeylonRequestHandler.ceylon:60)
at io.undertow.util.WorkerDispatcher$1.run(WorkerDispatcher.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
... 2 more
Thanks,
Matej.
11 years, 11 months