Partial work getting TCP logging testable, and fixing lots of race conditions.