fix - close stream when error