Skip to content
Merged
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion core/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ func (t *Task) GetTraits() Traits {
return Traits{}
}

// lock-free version of GetTraits
func (t *Task) getTraits() Traits {
if class := t.GetTaskClass(); class != nil {
if t.parent != nil {
return t.parent.GetTaskTraits()
}
}
return Traits{}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't like how it is literally the same code for GetTraits() and getTraits() except t.parent part. I'd probably make getTraits(*parentRole) and call it from GetTraits, because the t.GetParent() usage in this case is not thread safe either way. We call it twice, so if there is a change of a parent from other goroutine, we might get different results on both calls due to race condition. With this change we will at least alway address the same parent, even if it changes half during the GetTraits call.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

did you mean something like this?

// Returns a consolidated CommandInfo for this Task, based on Roles tree and
// Class.
func (t *Task) BuildTaskCommand(role parentRole) (err error) {
Expand Down Expand Up @@ -525,7 +535,7 @@ func (t *Task) SendEvent(ev event.Event) {
Hostname: t.hostname,
ClassName: t.className,
Path: t.getParentRolePath(),
Traits: traitsToPbTraits(t.GetTraits()),
Traits: traitsToPbTraits(t.getTraits()),
}

if t.parent == nil {
Expand Down