Source:
<code>public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryException { if (mustBeReadOnly != currentReadOnlyAsked && currentProtocol.inTransaction()) { throw new QueryException("Trying to set to read-only mode during a transaction"); } checkWaitingConnection(); <START> if (currentReadOnlyAsked != mustBeReadOnly) { <END> synchronized (currentReadOnlyUpdateLock) { if (currentReadOnlyAsked == mustBeReadOnly) { return; } else { currentReadOnlyAsked = mustBeReadOnly; } if (currentReadOnlyAsked) { if (currentProtocol.isMasterConnection()) { if (!isSecondaryHostFail()) { proxy.lock.lock(); try { syncConnection(this.masterProtocol, this.secondaryProtocol); currentProtocol = this.secondaryProtocol; return; } catch (QueryException e) { if (setSecondaryHostFail()) { addToBlacklist(secondaryProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } FailoverLoop.addListener(this); } } else { if (!currentProtocol.isMasterConnection()) { if (!isMasterHostFail()) { proxy.lock.lock(); try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; return; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } try { reconnectFailedConnection(new SearchFilter(true, false)); handleFailLoop(); proxy.lock.lock(); try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } catch (QueryException e) { FailoverLoop.removeListener(this); HostAddress failHost = (this.masterProtocol != null) ? this.masterProtocol.getHostAddress() : null; throwFailoverMessage(failHost, true, new QueryException("master " + masterProtocol.getHostAddress() + " connection failed"), false); } } } } } }</code><technical_language>@jentfoo switched AtomicBoolean a volatile a synchronized object combination. If AtomicBoolean is defunct, I remove it. I this is case. I recommend leaving AtomicBoolean is, problem is investigated. reads AtomicBoolean volatile variables in java: <LINK_1> <LINK_0></technical_language>

Target:
public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryException { if (mustBeReadOnly != currentReadOnlyAsked && currentProtocol.inTransaction()) { throw new QueryException("Trying to set to read-only mode during a transaction"); } checkWaitingConnection(); if (currentReadOnlyAsked != mustBeReadOnly) { proxy.lock.lock(); try { if (currentReadOnlyAsked == mustBeReadOnly) { return; } else { currentReadOnlyAsked = mustBeReadOnly; } if (currentReadOnlyAsked) { if (currentProtocol.isMasterConnection()) { if (!isSecondaryHostFail()) { proxy.lock.lock(); try { syncConnection(this.masterProtocol, this.secondaryProtocol); currentProtocol = this.secondaryProtocol; return; } catch (QueryException e) { if (setSecondaryHostFail()) { addToBlacklist(secondaryProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } FailoverLoop.addListener(this); } } else { if (!currentProtocol.isMasterConnection()) { if (!isMasterHostFail()) { try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; return; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } } try { reconnectFailedConnection(new SearchFilter(true, false)); handleFailLoop(); try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } } catch (QueryException e) { FailoverLoop.removeListener(this); HostAddress failHost = (this.masterProtocol != null) ? this.masterProtocol.getHostAddress() : null; throwFailoverMessage(failHost, true, new QueryException("master " + masterProtocol.getHostAddress() + " connection failed"), false); } } } } finally { proxy.lock.unlock(); } } }