-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protect object map from concurrent access #340
base: master
Are you sure you want to change the base?
Changes from 4 commits
f7b24ad
5951285
17e6ce7
b4472fc
6d9aa21
3da7206
0af72af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,29 @@ type defaultHandler struct { | |
defaultIntf map[string]*exportedIntf | ||
} | ||
|
||
func (h *defaultHandler) PathExists(path ObjectPath) bool { | ||
_, ok := h.objects[path] | ||
return ok | ||
func (h *defaultHandler) GetExportedObject(path ObjectPath) (*exportedObj, bool) { | ||
h.RLock() | ||
defer h.RUnlock() | ||
obj, ok := h.objects[path] | ||
return obj, ok | ||
} | ||
|
||
// GetAnExportedObject returns an exportedObj for an specific ObjectPath | ||
// A new exportedObj is creaated if none existed for ObjectPath | ||
ubkr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (h *defaultHandler) GetAnExportedObject(path ObjectPath) *exportedObj { | ||
ubkr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
h.RLock() | ||
defer h.RUnlock() | ||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be a write lock then. The race detector picked this up as well: https://github.com/godbus/dbus/actions/runs/4797626686/jobs/9033883115?pr=340#step:6:243 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So true. Fixed! |
||
obj, ok := h.objects[path] | ||
if !ok { | ||
obj = newExportedObject() | ||
h.objects[path] = obj | ||
} | ||
return obj | ||
} | ||
|
||
func (h *defaultHandler) introspectPath(path ObjectPath) string { | ||
h.RLock() | ||
defer h.RUnlock() | ||
subpath := make(map[string]struct{}) | ||
var xml bytes.Buffer | ||
xml.WriteString("<node>") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.