Skip to content

daemon: rename: don't reload endpoint from datastore#47195

Merged
thaJeztah merged 1 commit intomoby:masterfrom
akerouanton:fix-multiple-rename-error
Jan 23, 2024
Merged

daemon: rename: don't reload endpoint from datastore#47195
thaJeztah merged 1 commit intomoby:masterfrom
akerouanton:fix-multiple-rename-error

Conversation

@akerouanton
Copy link
Member

@akerouanton akerouanton commented Jan 23, 2024

- What I did

Commit 8b7af1d added some code to update the DNSNames of all endpoints attached to a sandbox by loading a new instance of each affected endpoints from the datastore through a call to Network.EndpointByID().

This method then calls Network.getEndpointFromStore(), that in turn calls store.GetObject(), which then calls cache.get(), which calls o.CopyTo(kvObject). This effectively creates a fresh new instance of an Endpoint. However, endpoints are already kept in memory by Sandbox, meaning we now have two in-memory instances of the same Endpoint.

As it turns out, libnetwork is built around the idea that no two objects representing the same thing should live in-memory, otherwise breaking mutex locking and optimistic locking (as both instances will have a drifting version tracking ID -- dbIndex in libnetwork parliance).

In this specific case, this bug materializes by container rename failing when applied a second time for a given container. An integration test is added to make sure this doesn't happen in the future.

- How I did it

This is a quick-fix; instead of loading endpoints through Network.EndpointByID(), Sandbox.getEndpoint() was made public and is now used. I also added a comment on Network.EndpointByID() saying this method should never be used -- and actually it should be removed in a follow-up.

- How to verify it

I added an integration test to test that docker rename can be called multiple times for the same container.

- Description for the changelog

  • Fix a bug that prevented a container from being renamed twice

Copy link
Contributor

@robmry robmry left a comment

Choose a reason for hiding this comment

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

LGTM

@akerouanton akerouanton force-pushed the fix-multiple-rename-error branch from a838661 to 403e471 Compare January 23, 2024 21:49
Commit 8b7af1d added some code to update the DNSNames of all
endpoints attached to a sandbox by loading a new instance of each
affected endpoints from the datastore through a call to
`Network.EndpointByID()`.

This method then calls `Network.getEndpointFromStore()`, that in
turn calls `store.GetObject()`, which then calls `cache.get()`,
which calls `o.CopyTo(kvObject)`. This effectively creates a fresh
new instance of an Endpoint. However, endpoints are already kept in
memory by Sandbox, meaning we now have two in-memory instances of
the same Endpoint.

As it turns out, libnetwork is built around the idea that no two objects
representing the same thing should leave in-memory, otherwise breaking
mutex locking and optimistic locking (as both instances will have a drifting
version tracking ID -- dbIndex in libnetwork parliance).

In this specific case, this bug materializes by container rename failing
when applied a second time for a given container. An integration test is
added to make sure this won't happen again.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
@akerouanton akerouanton force-pushed the fix-multiple-rename-error branch from 403e471 to 80c44b4 Compare January 23, 2024 21:53
@thaJeztah
Copy link
Member

nice find on the sb.getendPoint @corhere !

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker container rename fails

4 participants