Fix #76 avoid possible thread leak on shutdown