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

I think all of closing sequence should be executed atomically so I think only using atomic boolean is insufficient.