fix to wait input stream end