Skip to content

Commit

Permalink
ZOOKEEPER-4514: ClientCnxnSocketNetty throwing NPE
Browse files Browse the repository at this point in the history
Moved channel object null check to sendPkt method to cover all calling scenarios

Author: Mohammad Arshad <arshad@apache.org>

Reviewers: Mate Szalay-Beko <symat@apache.org>

Closes apache#1854 from arshadmohammad/ZOOKEEPER-4514-npe

(cherry picked from commit d5876e8)
Signed-off-by: Mohammad Arshad <arshad@apache.org>
  • Loading branch information
arshadmohammad authored and desaikomal committed Jun 17, 2023
1 parent 97f5c72 commit 8f3127c
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private void addBack(Packet head) {
* @return a ChannelFuture that will complete when the write operation
* succeeds or fails.
*/
private ChannelFuture sendPktAndFlush(Packet p) {
private ChannelFuture sendPktAndFlush(Packet p) throws IOException {
return sendPkt(p, true);
}

Expand All @@ -314,7 +314,7 @@ private ChannelFuture sendPktAndFlush(Packet p) {
* @return a ChannelFuture that will complete when the write operation
* succeeds or fails.
*/
private ChannelFuture sendPktOnly(Packet p) {
private ChannelFuture sendPktOnly(Packet p) throws IOException {
return sendPkt(p, false);
}

Expand All @@ -325,7 +325,10 @@ private ChannelFuture sendPktOnly(Packet p) {
}
};

private ChannelFuture sendPkt(Packet p, boolean doFlush) {
private ChannelFuture sendPkt(Packet p, boolean doFlush) throws IOException {
if (channel == null) {
throw new IOException("channel has been closed");
}
// Assuming the packet will be sent out successfully. Because if it fails,
// the channel will close and clean up queues.
p.createBB();
Expand All @@ -336,15 +339,15 @@ private ChannelFuture sendPkt(Packet p, boolean doFlush) {
return result;
}

private void sendPrimePacket() {
private void sendPrimePacket() throws IOException {
// assuming the first packet is the priming packet.
sendPktAndFlush(outgoingQueue.remove());
}

/**
* doWrite handles writing the packets from outgoingQueue via network to server.
*/
private void doWrite(Queue<Packet> pendingQueue, Packet p, ClientCnxn cnxn) {
private void doWrite(Queue<Packet> pendingQueue, Packet p, ClientCnxn cnxn) throws IOException {
updateNow();
boolean anyPacketsSent = false;
while (true) {
Expand Down Expand Up @@ -374,9 +377,6 @@ private void doWrite(Queue<Packet> pendingQueue, Packet p, ClientCnxn cnxn) {

@Override
void sendPacket(ClientCnxn.Packet p) throws IOException {
if (channel == null) {
throw new IOException("channel has been closed");
}
sendPktAndFlush(p);
}

Expand Down

0 comments on commit 8f3127c

Please sign in to comment.