Fix a bug that causes random test failures