fix a bug of writing closed chan