[SPARK-3106] Fix the race condition issue about Connection and ConnectionManager

Another thing to keep in mind is that this is a hot loop (as described in the comment below). Even without contention, I think `synchronized` adds a memory fence and this may impact performance. @rxin do you have some shuffle benchmarks which can check performance ?