Fix intermittent long teardown

This fixes #172.