You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2022/10/28 22:00:08 UTC

[GitHub] [zookeeper] cnauroth commented on pull request #1774: ZOOKEEPER-4409 NullPointerException in SendAckRequestProcessor

cnauroth commented on PR #1774:
URL: https://github.com/apache/zookeeper/pull/1774#issuecomment-1295509378

   Assuming the cause is as described in https://github.com/apache/zookeeper/pull/1774#issuecomment-993437244 , then I'm not sure this patch would completely prevent NPEs. With this patch, we could have 2 independent threads concurrently calling `Learner#closeSockSync()`:
   
   ```
       void closeSockSync() {
           try {
               long startTime = Time.currentElapsedTime();
               if (sock != null) {
                   sock.close();
                   sock = null;
               }
               ServerMetrics.getMetrics().SOCKET_CLOSING_TIME.add(Time.currentElapsedTime() - startTime);
           } catch (IOException e) {
               LOG.warn("Ignoring error closing connection to leader", e);
           }
       }
   ```
   
    I don't believe there is any locking in effect around this operation, so it would be possible that both thread 1 and thread 2 make it past the `if (sock != null)` check, thread 1 closes and nulls the variable, and then thread 2 gets the NPE when it attempts `sock.close()`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org