Releasing the lock too early was allowing other async processes to sneak in and start running before the current process was completely shut down. The only symptom seems to have been mixed up log messages so not a very serious issue.