When we close an index manager, we need to wait for pending works to finish executing.
In the Elasticsearch backend, unfortunately, we can currently only wait for works of the whole backend to finish executing. This means that, when we close an index manager but another index manager is still open, the wait could theoretically last forever if the open index manager continually pushes works.
In a more realistic scenario, it's possible that index manager closing lasts longer because of this flaw.
To solve this, we should change the way waiting is implemented in org.hibernate.search.engine.backend.orchestration.spi.BatchingExecutor#awaitCompletion. See the TODO on that method.
Note this improvement might not be worth it if we only allow to close index managers when Hibernate Search shuts down and if we implement HSEARCH-3084. If we allow to close index managers at runtime, however, it could bring some improvement.