close stream when closing device