Fixed the issue in stream close handling