Backport of test_last_endpoint shutdown fix, resolves LIBZMQ-462