while loop breaks in channel code and break condition not met