Skip to content

Lock agent access in addDriverWatches#1457

Merged
mavenugo merged 1 commit intomoby:masterfrom
aboch:pnc
Sep 21, 2016
Merged

Lock agent access in addDriverWatches#1457
mavenugo merged 1 commit intomoby:masterfrom
aboch:pnc

Conversation

@aboch
Copy link
Copy Markdown
Contributor

@aboch aboch commented Sep 20, 2016

Related to moby/moby#25848

Signed-off-by: Alessandro Boch aboch@docker.com

Signed-off-by: Alessandro Boch <aboch@docker.com>
Comment thread agent.go
for _, tableName := range n.driverTables {
ch, cancel := c.agent.networkDB.Watch(tableName, n.ID(), "")
c.Lock()
if c.agent == nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You need to retrieve agent within lock and only use that after. Not c.agent anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But I want to keep the current logic where the lock is held until after c.agent.driverCancelFuncs map is modified.

If you are suggesting to add a local variable even thoug we will use it inside a locked scope, I do not see the need.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No the problem is the c.agent.networkDB and c.agent.driverCancelFuncs access below will crash if c.agent is made nil during that time. That is the actual root cause for this crash.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

c.agent cannot be made nil if we hold the lock.
This change adds some coordination, so that when we access c.agent and we assert it is not nil, it we can modify its members assured it cannot be made nil in the meanwhile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah missed that you are still holding the lock when you are access the agent. Changes look good.

Copy link
Copy Markdown
Contributor

@mrjana mrjana left a comment

Choose a reason for hiding this comment

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

LGTM

@mavenugo
Copy link
Copy Markdown
Contributor

LGTM

@mavenugo mavenugo merged commit e69621c into moby:master Sep 21, 2016
@aboch aboch deleted the pnc branch November 16, 2016 18:33
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.

4 participants