3828: Remove duplicate "write pidfile" block.
3828: Use defer to close pidfile. Avoids leftover pidfile if Listen fails.
3828: Wait for listener to start before connecting to it. Fix test
panic in listener.Close() when listener does not exist.
Merge branch '3828-keepproxy-race' closes #3828