More race condition prevention

Isolate channel operations inside locks to prevent race between send and close.