Skip to content

[Backport 17.12] Added required call to allocate VIPs when endpoints are restored#2472

Closed
fcrisciani wants to merge 2 commits into
moby:bump_v17.12from
fcrisciani:backport_17.06
Closed

[Backport 17.12] Added required call to allocate VIPs when endpoints are restored#2472
fcrisciani wants to merge 2 commits into
moby:bump_v17.12from
fcrisciani:backport_17.06

Conversation

@fcrisciani
Copy link
Copy Markdown

@fcrisciani fcrisciani commented Dec 15, 2017

From original PR (#2468):
Tracking down libnetwork/1790#issuecomment-308222053. The report is that if on a single node several services are started, and if this node is then rebooted, all the services appear to come back but some of them are no longer reachable.

On probing, the cause turned out to be an invalid assignment of IP addresses to services when they were restored. Specifically, the same IP address was assigned to one service's VIP and also a different service's endpoint. The result was that packets got delivered to the wrong container and caused symptoms like services or ports unreachable.

This is very likely to also be the cause of moby/#35675 and other duplicate-IP or overlapping IP issues.

The reason for this problem seems to be that the code path followed when services are restored, at no point contacts or informs IPAM about the IP addresses used as the restored service's VIP. So IPAM thinks that those IP addresses are still available and hands them out to endpoints and new services, causing the observed chaos.

To work out the right fix, I compared the code path when a service is created from the CLI to the code path when a service is restored on reboot. To me this fix is the bit that should have always been on the restore path but was omitted. With this fix IPAM gets correctly informed and it's state is consistent with what I see on the network.

I have tested this fix on a single node running several services and when there multiple nodes with multiple managers running many services (specifically 2 nodes and 2 managers). In both cases, without the fix a reboot would cause IP address overlaps on the ingress network. With the fix there are no overlaps.

While the fix seems to work, I'm not sure if it is at exactly the right point in this function, or indeed if it is the right or complete fix. Please take a look and let me know.

On leader change or leader reboot the restore logic in the allocator
was allocating overlapping IP address for VIPs and Endpoints in the
ingress network.  The fix added as part of this commit ensures
that during restore we allocate the existing VIP and endpoint.

Signed-off-by: Balraj Singh <balrajsingh@ieee.org>
(cherry picked from commit 5fd25d2)
@fcrisciani
Copy link
Copy Markdown
Author

@balrajsingh @abhi @dperny for final blessing

Copy link
Copy Markdown
Contributor

@abhi abhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Balraj Singh <balrajsingh@ieee.org>
(cherry picked from commit 2397ddf)
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 15, 2017

Codecov Report

Merging #2472 into bump_v17.12 will increase coverage by 5.52%.
The diff coverage is 0%.

@@               Coverage Diff               @@
##           bump_v17.12    #2472      +/-   ##
===============================================
+ Coverage         61.8%   67.32%   +5.52%     
===============================================
  Files              128       80      -48     
  Lines            21107    11487    -9620     
===============================================
- Hits             13045     7734    -5311     
+ Misses            6664     2963    -3701     
+ Partials          1398      790     -608

@fcrisciani
Copy link
Copy Markdown
Author

CI error:

time="2017-12-15T19:40:14Z" level=error msg="task allocation failure" error="failed to retrieve network testID3 while allocating task testTaskID3" 
time="2017-12-15T19:40:15Z" level=error msg="Failed allocation for network testID5" error="failed while allocating driver state for network testID5: could not obtain vxlan id for pool 10.0.4.0/24: requested bit is already allocated" 
time="2017-12-15T19:40:15Z" level=error msg="task allocation failure" error="network testID5 attached to task testTaskID6 not allocated yet" 
time="2017-12-15T19:40:15Z" level=error msg="Failed allocation for service testServiceID4" error="requested bit is already allocated" 
time="2017-12-15T19:40:15Z" level=error msg="task allocation failure" error="service testServiceID4 to which this task testTaskID7 belongs has pending allocations" 
--- FAIL: TestNodeAllocator (0.02s)
	allocator_test.go:1047: timed out before watchNode found expected node state
FAIL
coverage: 71.5% of statements
FAIL	github.com/docker/swarmkit/manager/allocator	4.167s

Tried a couple of times, giving up, looks like was also failing on master

@dperny
Copy link
Copy Markdown
Collaborator

dperny commented Dec 15, 2017

when i merged the original PR all tests were succeeding...

@fcrisciani
Copy link
Copy Markdown
Author

@dperny yeah but as far as I know @balrajsingh triggered the CI several times

@fcrisciani
Copy link
Copy Markdown
Author

@balrajsingh can you take a look? is it possible that is an artifact of running the tests in parallel?

@balrajsingh
Copy link
Copy Markdown
Contributor

@fcrisciani This particular test (TestNodeAllocator) seems to pass sometimes and fail at other times on the CI.
On my local machine it seems to mostly fail, but it also fails when I go back to previous versions. I've checked back till about early Oct and in my env this test is currently failing in all of them.
I also tried removing all other tests in that file but the test still fails, though without the allocation failure message.

@abhi
Copy link
Copy Markdown
Contributor

abhi commented Dec 18, 2017

@balrajsingh I looked at the test cases. It looks like this error is expected.

time="2017-12-15T19:40:14Z" level=error msg="task allocation failure" error="failed to retrieve network testID3 while allocating task testTaskID3" 
time="2017-12-15T19:40:15Z" level=error msg="Failed allocation for network testID5" error="failed while allocating driver state for network testID5: could not obtain vxlan id for pool 10.0.4.0/24: requested bit is already allocated" 
time="2017-12-15T19:40:15Z" level=error msg="task allocation failure" error="network testID5 attached to task testTaskID6 not allocated yet" 
time="2017-12-15T19:40:15Z" level=error msg="Failed allocation for service testServiceID4" error="requested bit is already allocated" 
time="2017-12-15T19:40:15Z" level=error msg="task allocation failure" error="service testServiceID4 to which this task testTaskID7 belongs has pending allocations" 

So definitely thats not an issue.If you run go test -run TestNodeAllocator, you see the test failing ? I just pulled the master and ran a bunch of times and I don't see any test failing.

@seemethere
Copy link
Copy Markdown

This can probably be closed

@fcrisciani
Copy link
Copy Markdown
Author

merged as another PR

@fcrisciani fcrisciani closed this Dec 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants