Library sometimes hanged on shutdown