On 08/01/2015 13:46, Rémy Maucherat wrote: > 2015-01-08 14:10 GMT+01:00 <ma...@apache.org>: > >> @@ -766,32 +776,120 @@ public class Nio2Endpoint extends Abstra >> this.writeCompletionHandler = new CompletionHandler<Integer, >> ByteBuffer>() { >> @Override >> public void completed(Integer nBytes, ByteBuffer >> attachment) { >> - if (nBytes.intValue() < 0) { >> - failed(new EOFException(), attachment); >> - } else if (attachment.hasRemaining()) { >> - getSocket().write(attachment, getTimeout(), >> - TimeUnit.MILLISECONDS, attachment, >> writeCompletionHandler); >> - } else { >> - writePending.release(); >> - if (!Nio2Endpoint.isInline()) { >> - >> getEndpoint().processSocket(Nio2SocketWrapper.this, >> SocketStatus.OPEN_WRITE, false); >> + boolean notify = false; >> + synchronized (writeCompletionHandler) { >> + if (nBytes.intValue() < 0) { >> + failed(new >> EOFException(sm.getString("iob.failedwrite")), attachment); >> + } else if >> (Nio2SocketWrapper.this.bufferedWrites.size() > 0) { >> + // Continue writing data using a gathering >> write >> + ArrayList<ByteBuffer> arrayList = new >> ArrayList<>(); >> + if (attachment.hasRemaining()) { >> + arrayList.add(attachment); >> + } >> + for (ByteBufferHolder buffer : >> Nio2SocketWrapper.this.bufferedWrites) { >> + buffer.flip(); >> + arrayList.add(buffer.getBuf()); >> + } >> + Nio2SocketWrapper.this.bufferedWrites.clear(); >> + ByteBuffer[] array = arrayList.toArray(new >> ByteBuffer[arrayList.size()]); >> + >> Nio2SocketWrapper.this.getSocket().write(array, 0, array.length, >> + Nio2SocketWrapper.this.getTimeout(), >> TimeUnit.MILLISECONDS, >> + array, >> gatheringWriteCompletionHandler); >> + } else if (attachment.hasRemaining()) { >> + // Regular write >> + >> Nio2SocketWrapper.this.getSocket().write(attachment, >> Nio2SocketWrapper.this.getTimeout(), >> + TimeUnit.MILLISECONDS, attachment, >> writeCompletionHandler); >> + } else { >> + // All data has been written >> + if (interest && !Nio2Endpoint.isInline()) { >> + interest = false; >> + notify = true; >> + } >> + writePending.release(); >> } >> } >> > There's a big deadlock risk if the recursion if incomplete and error > processing are inside the sync.
I came across some of those while doing the refactoring. I think - as of r1650289 - they are addressed but it is possible I missed something. If you have a particular sequence in mind then I'd be happy to take another look. Mark > > Rémy > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org