https://bugs.openldap.org/show_bug.cgi?id=8901
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|VERIFIED |CONFIRMED Resolution|FEEDBACK |---
--- Comment #5 from Howard Chu hyc@openldap.org --- The problem is because ldap_pvt_thread_pool_close() doesn't actually know when the last thread has exited. The last thread does a cond_signal() to tell that it is exiting, but there's additional time between that and when the thread actually returns (or calls pthread_exit). And LMDB's own reader_dest function doesn't execute until the actual pthread_exit occurs. So when ldap_pvt_thread_pool_close() returns, worker threads may still be running. Then when backend_shutdown is called, which invokes back-mdb's shutdown and eventual mdb_env_close(), it may get there before the worker threads have completed, and so destroy the environment while worker threads are still trying to clear their reader slots.
A proper fix would require some rewriting of the thread_pool code to track thread creation and termination explicitly. A workaround for now would be to insert a sleep(1) at the end of ldap_pvt_thread_pool_close().