mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
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:
@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user