From 1ddb473debd2c14b45a67d480941f0ade00e101d Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 23 Nov 2024 16:35:50 +0200 Subject: [PATCH] monitors/alsa: handle node activation failure When node activation fails, it won't be created and its object-removed signal can be called with some properties missing. This breaks node name deduplication, causing error wplua: [string "alsa.lua"]:182: attempt to concatenate a nil value (local 'node_name') It occurs e.g. when switching ALSA device profile, while some application has opened the device with ALSA and is keeping it busy. Fix by handling the activation failure, and tolerating missing property in object-removed. --- src/scripts/monitors/alsa.lua | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/scripts/monitors/alsa.lua b/src/scripts/monitors/alsa.lua index 15d20f42..57925487 100644 --- a/src/scripts/monitors/alsa.lua +++ b/src/scripts/monitors/alsa.lua @@ -108,6 +108,8 @@ function createNode(parent, id, obj_type, factory, properties) properties["node.name"] = name .. "." .. counter log:info ("deduplicating node name -> " .. properties["node.name"]) end + else + log:info ("Creating node " .. properties["node.name"]) end -- and a nick @@ -164,7 +166,16 @@ function createNode(parent, id, obj_type, factory, properties) -- create the node local node = Node("adapter", properties) - node:activate(Feature.Proxy.BOUND) + node:activate(Feature.Proxy.BOUND, function (_, err) + if err then + log:warning ("Failed to create " .. properties ["node.name"] + .. ": " .. tostring(err)) + + -- if it fails, object-removed gets called with missing + -- properties, so clean up already here + node_names_table [properties ["node.name"]] = nil + end + end) parent:store_managed_object(id, node) end @@ -179,8 +190,12 @@ function createDevice(parent, id, factory, properties) end local node_name = node.properties["node.name"] - log:info ("Removing node " .. node_name) - node_names_table[node_name] = nil + if node_name ~= nil then + log:info ("Removing node " .. node_name) + node_names_table[node_name] = nil + else + log:info ("Removing node with missing node.name") + end end) device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND) parent:store_managed_object(id, device)