Zookeeper Session Expired Exception

When I set a breakpoint to debug through the code, I get a Zookeeper Session Expired Exception

It's important to note that Zookeeper clients maintain a stateful connection, similar to a database connection (connections to Solr, itself, are stateless).  The SolrJ API allows for SolrCloud interactions.  SolrCloud is simply a clustered deployment option for Solr that relies on Zookeeper for cluster management and node discovery.  The CloudSolrClient implementation of SolrClient from SolrJ, indeed, maintains a stateful connection to Zookeeper as well, and allows us direct access to the Zookeeper client and underlying connection.  Broadleaf uses this connection to maintain distributed locks that prevent multiple threads or nodes from executing concurrently, especially with respect to Solr indexing.  The Zookeeper client pings the Zookeeper server which notifies the server that the client is still active.  If the Zookeeper client fails to ping the server for a period of time, then the server considers that client expired.

The logs, for example, might look like this:

Caused by org.apache.zookeeper.KeeperException$SessionExpiredException : KeeperErrorCode = Session expired for /indexer-locks/CATALOG

When you have a breakpoint engaged, it is important to ensure that the breakpoint is configured to pause the current thread and not the entire system.  When the entire system is paused, the background threads that ping the Zookeeper server stop working, and Zookeeper then considers those connections timed out.  If you set a breakpoint, wherever possible, you should ensure that it pauses the current thread and not the entire JVM.  This will help prevent Zookeeper exceptions indicating that the session is expired.  This is especially true when debugging the Search Indexer functionality, but is with other flows, including Catalog Browse.

In IntelliJ, for example, you can right-click on the breakpoint to configure it.  Make sure it is set to Thread instead of System: