Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ func (n *network) addDriverWatches() {

c := n.getController()
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.

c.Unlock()
return
}
ch, cancel := c.agent.networkDB.Watch(tableName, n.ID(), "")
c.agent.driverCancelFuncs[n.ID()] = append(c.agent.driverCancelFuncs[n.ID()], cancel)
c.Unlock()

Expand Down