Commit b3b10db5 authored by Julian Bouzas's avatar Julian Bouzas
Browse files

policy: don't link endpoints on startup

Sometimes the default device node might not exist when reevaluating endpoints
for the first time on startup, so the policy would link endpoints to another
device node. Then, the default device node appears and the policy moves the
endpoints to the default device node while the previous link has not finish its
activation yet. This race condition can cause endpoint links to fail when being
activated. Delaying the reevaluation of endpoint links until the first client
link is created avoids this issue.
parent 5756d889
Pipeline #323072 passed with stages
in 1 minute and 11 seconds
...@@ -176,15 +176,21 @@ end ...@@ -176,15 +176,21 @@ end
default_nodes = Plugin.find("default-nodes-api") default_nodes = Plugin.find("default-nodes-api")
siendpoints_om = ObjectManager { Interest { type = "SiEndpoint" }} siendpoints_om = ObjectManager { Interest { type = "SiEndpoint" }}
silinkables_om = ObjectManager { Interest { type = "SiLinkable", silinkables_om = ObjectManager { Interest { type = "SiLinkable",
-- only handle si-audio-adapter and si-node -- only handle device si-audio-adapter items
Constraint { Constraint { "si.factory.name", "=", "si-audio-adapter", type = "pw-global" },
"si.factory.name", "c", "si-audio-adapter", "si-node", type = "pw-global" }, Constraint { "is.device", "=", true, type = "pw-global" },
} }
} }
silinks_om = ObjectManager { Interest { type = "SiLink", silinks_om = ObjectManager { Interest { type = "SiLink",
-- only handle links created by this policy -- only handle links created by this policy
Constraint { "is.policy.endpoint.device.link", "=", true, type = "pw-global" }, Constraint { "is.policy.endpoint.device.link", "=", true, type = "pw-global" },
} } } }
clientlinks_om = ObjectManager {
Interest {
type = "SiLink",
Constraint { "is.policy.endpoint.client.link", "=", true },
},
}
-- listen for default node changes if config.follow is enabled -- listen for default node changes if config.follow is enabled
if config.follow then if config.follow then
...@@ -193,10 +199,20 @@ if config.follow then ...@@ -193,10 +199,20 @@ if config.follow then
end) end)
end end
silinkables_om:connect("objects-changed", function (om) -- start reevaluating endpoints when the first client link is created
clientlinks_om:connect("object-added", function (om, l)
reevaluateLinks () reevaluateLinks ()
-- stop listening to client links from now on
clientlinks_om = nil
-- only reevaluate endpoints when device nodes change from now on
silinkables_om:connect("objects-changed", function (om)
reevaluateLinks ()
end)
end) end)
siendpoints_om:activate() siendpoints_om:activate()
silinkables_om:activate() silinkables_om:activate()
silinks_om:activate() silinks_om:activate()
clientlinks_om:activate()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment