close stream on connecting errors
Add missing import