Github user madrob commented on the pull request:

    https://github.com/apache/curator/pull/51#issuecomment-73259604
  
    Looks like I neglected to respond to this for a while. Here is why I think 
the logic is faulty.
    
    T2: `processResult()` method entry
    T2: `synchronized (backgroundTaskMonitor)` acquire lock
    T2: `if (state.get().equals(State.CLOSED)) { }` evaluates false
    T1: `close()` method entry
    T1: `if ( state.compareAndSet(State.STARTED, State.CLOSED) )` evaluates true
    T1: `listeners.clear()`
    T1:  
`client.getConnectionStateListenable().removeListener(connectionStateListener)`
    T1 suspends waiting for the lock
    T2: `processBackgroundResult(event)` gets called on a closed connection
    
    I think the solution is to put all of the `close()` method into the 
`synchronized` block, but that is not a super appealing answer. Maybe it will 
be fine though.
    
    The other concern is that now we can only process a single background event 
at a time, which seems like it could be a pretty high price to pay.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to