Fix deadlock during shutdown

Pretty sure this will do the trick