Other: Fix race conditions in internal/dialer

Some race conditions came from the tests themselves. But we had a race
condition reading the proxyAddress; this change protects it with a
mutex.
This commit is contained in:
James Houlahan
2022-10-24 16:41:17 +02:00
parent d6260d960c
commit 350544e801
3 changed files with 29 additions and 9 deletions

View File

@ -77,9 +77,11 @@ func formatAsAddress(rawURL string) string {
// DialTLSContext dials the given network/address. If it fails, it retries using a proxy.
func (d *ProxyTLSDialer) DialTLSContext(ctx context.Context, network, address string) (net.Conn, error) {
d.locker.RLock()
if address == d.directAddress {
address = d.proxyAddress
}
d.locker.RUnlock()
conn, err := d.dialer.DialTLSContext(ctx, network, address)
if err == nil || !d.allowProxy {
@ -90,6 +92,9 @@ func (d *ProxyTLSDialer) DialTLSContext(ctx context.Context, network, address st
return nil, err
}
d.locker.RLock()
defer d.locker.RUnlock()
return d.dialer.DialTLSContext(ctx, network, d.proxyAddress)
}