syncthing/lib/nat
greatroar 8265dac127
lib/nat: Fix race condition in Mapping (#8042)
The locking protocol in nat.Mapping was racy:

* Mapping.addressMap RLock'd, but then returned a map shared between
  caller and Mapping, so the lock didn't do anything.

* Operations inside Service.{verifyExistingMappings,acquireNewMappings}
  would lock the map for every update, but that means callers to
  Mapping.ExternalAddresses can be looping over the map while the
  Service methods are concurrently modifying it. When the Go runtime
  detects that happening, it panics.

* Mapping.expires was read and updated without locking.

The Service methods now lock the map once and release the lock only when
done.

Also, subscribers no longer get the added and removed addresses, because
none of them were using the information. This was changed for a previous
attempt to retain the fine-grained locking and not reverted because it
simplifies the code.
2021-11-22 08:29:44 +01:00
..
debug.go all, lib/logger: Refactor SetDebug calls (#6054) 2019-10-04 13:03:34 +02:00
interface.go lib: More contextification (#6343) 2020-02-24 21:57:15 +01:00
registry.go all: Use context in lib/dialer (#6177) 2019-11-26 07:39:51 +00:00
service.go lib/nat: Fix race condition in Mapping (#8042) 2021-11-22 08:29:44 +01:00
structs_test.go all: Refactor preparing configuration (#7127) 2020-11-20 14:21:54 +01:00
structs.go lib/nat: Fix race condition in Mapping (#8042) 2021-11-22 08:29:44 +01:00