[ https://issues.apache.org/jira/browse/ZOOKEEPER-2091?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14244861#comment-14244861 ]
Camille Fournier commented on ZOOKEEPER-2091: --------------------------------------------- I'm all the way in the bottom of this code and don't even remember the invariants. Why don't we wait till all the bytes are flushed to the buffer if we don't read anything until that's done? FWIW, I looked into the depth's of Netty's NIO socket handling. In particular to verify that Netty sockets will sometimes switch to reading before all of the outgoing bytes are written, which they will. I thought it was interesting though that they also configure a "writeSpinCount" that lets them try to flush all bytes a configurable number of times before going back to the selector to do other IO. Might be something worth considering. Or, you know, not doing this socket stuff ourselves at all and just using netty :) https://github.com/netty/netty/blob/0eb059bf58642f3c06144e1ea4a9d6c7632eb4d5/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java#L198 In conclusion, I think that it may not matter much either way but probably we should only add this to the SendPacket method. > Possible logic error in ClientCnxnSocketNIO > ------------------------------------------- > > Key: ZOOKEEPER-2091 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2091 > Project: ZooKeeper > Issue Type: Bug > Components: java client > Affects Versions: 3.4.6 > Reporter: Cheng > Assignee: Rakesh R > Fix For: 3.5.1 > > Attachments: ZOOKEEPER-2091.patch > > > When SASL authentication is enabled, the ZooKeeper client will finally call > ClientCnxnSocketNIO#sendPacket(Packet p) to send a packet to server: > @Override > void sendPacket(Packet p) throws IOException { > SocketChannel sock = (SocketChannel) sockKey.channel(); > if (sock == null) { > throw new IOException("Socket is null!"); > } > p.createBB(); > ByteBuffer pbb = p.bb; > sock.write(pbb); > } > One problem I can see is that the sock is non-blocking, so when the sock's > output buffer is full(theoretically), only part of the Packet is sent out and > the communication will break. -- This message was sent by Atlassian JIRA (v6.3.4#6332)