You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ar...@apache.org on 2022/04/08 16:39:45 UTC
[zookeeper] branch branch-3.8 updated: ZOOKEEPER-4514: ClientCnxnSocketNetty throwing NPE
This is an automated email from the ASF dual-hosted git repository.
arshad pushed a commit to branch branch-3.8
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/branch-3.8 by this push:
new f28d16739 ZOOKEEPER-4514: ClientCnxnSocketNetty throwing NPE
f28d16739 is described below
commit f28d16739a3baefcf5679f3b4343f12a49df0a19
Author: Mohammad Arshad <ar...@apache.org>
AuthorDate: Fri Apr 8 22:08:55 2022 +0530
ZOOKEEPER-4514: ClientCnxnSocketNetty throwing NPE
Moved channel object null check to sendPkt method to cover all calling scenarios
Author: Mohammad Arshad <ar...@apache.org>
Reviewers: Mate Szalay-Beko <sy...@apache.org>
Closes #1854 from arshadmohammad/ZOOKEEPER-4514-npe
(cherry picked from commit d5876e88d6bab3cc1cee04f996b9804ff21581cb)
Signed-off-by: Mohammad Arshad <ar...@apache.org>
---
.../java/org/apache/zookeeper/ClientCnxnSocketNetty.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java
index 2686feddc..df5397855 100755
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java
@@ -304,7 +304,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket {
* @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);
}
@@ -314,7 +314,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket {
* @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);
}
@@ -325,7 +325,10 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket {
}
};
- 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();
@@ -336,7 +339,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket {
return result;
}
- private void sendPrimePacket() {
+ private void sendPrimePacket() throws IOException {
// assuming the first packet is the priming packet.
sendPktAndFlush(outgoingQueue.remove());
}
@@ -344,7 +347,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket {
/**
* 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) {
@@ -374,9 +377,6 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket {
@Override
void sendPacket(ClientCnxn.Packet p) throws IOException {
- if (channel == null) {
- throw new IOException("channel has been closed");
- }
sendPktAndFlush(p);
}