Made reconnection code thread-safer by using sync.Once