moby/distribution
Aaron Lehmann 3e2b50ccaa Fix watching a released transfer
Things could go wrong if Watch was called after the last existing
watcher was released. The call to Watch would succeed even though it was
not really adding a watcher, and the corresponding call to Release would
close hasWatchers a second time.

The fix for this is twofold:

1. We allow transfers to gain new watchers after the watcher count has
touched zero. This means that the channel returned by Released should
not be closed until all watchers have been released AND the transfer is
no longer tracked by the transfer manager, meaning it won't be possible
for additional calls to Watch to race with closing the channel returned
by Released.

The Transfer interface has a new method called Close so the transfer can
know when the transfer manager no longer references it.

Remove the Cancel method. It's not used and should not be exported.

2. Even though (1) makes it possible to add watchers after all the
previous watchers have been released, we want to avoid doing this in
practice. A transfer that has had all its watchers released is in the
process of being cancelled, and attaching to one of these will never be
the correct behavior. Add a check if a watcher is attaching to a
cancelled transfer.  In this case, wait for the transfer to be removed
from the map and try again. This will ensure correct behavior when a
watcher tries to attach during the race window.

Either (1) or (2) should be sufficient to fix the race involved here,
but the combination is the most correct approach. (1) fixes the
low-level plumbing to be resilient to the race condition, and (2) avoids
using it in a racy way.

Fixes #19606

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2016-01-25 13:28:02 -08:00
..
fixtures/validate_manifest Add distribution package 2015-11-24 09:40:24 -08:00
metadata Changes cross-repository blob mounting to a blob Create option 2016-01-14 14:26:03 -08:00
xfer Fix watching a released transfer 2016-01-25 13:28:02 -08:00
pull.go Revert reporting of multiple pull errors 2016-01-18 15:49:08 -08:00
pull_v1.go Make v1 pull/push output consistent with v2 2015-12-16 15:02:24 -08:00
pull_v2.go Changes cross-repository blob mounting to a blob Create option 2016-01-14 14:26:03 -08:00
pull_v2_test.go Add schema2 pull support 2016-01-08 17:24:21 -08:00
pull_v2_unix.go Add distribution package 2015-11-24 09:40:24 -08:00
pull_v2_windows.go Add distribution package 2015-11-24 09:40:24 -08:00
push.go Changes cross-repository blob mounting to a blob Create option 2016-01-14 14:26:03 -08:00
push_v1.go Make v1 pull/push output consistent with v2 2015-12-16 15:02:24 -08:00
push_v2.go Fixes layer MediaTypes in manifests created from a cross-repository push 2016-01-20 12:23:16 -08:00
registry.go Merge pull request #19551 from aaronlehmann/fix-retry-on-enospc 2016-01-21 15:37:50 -05:00
registry_unit_test.go Modify import paths to point to the new engine-api package. 2016-01-06 19:48:59 -05:00