Solve race condition while reading a closed stream frame