There is a deadlock that can occur when the concurrent runtime shuts down. This patch adds a test and fix. Fixes #401.