Lua script hangs when monitoring link in paused state
I was trying out a script I made in Lua and noticed that sometimes it hangs. After trying to make a minimal reproducible example I noticed that the reason it hangs is because I have a paused/suspended link between nodes.
Minimal reproduction:
-
Make a link get paused state. For example, leave a Youtube video paused in Firefox for more than 10 seconds.
-
Run the following script:
wpexec /dev/stdin <<EOM
om = ObjectManager {
Interest { type="link" }
}
om:connect("installed", function(om)
print("INSTALLED")
Core.quit()
end)
om:activate()
EOM
The result:
INSTALLED
wont be printed until you send SIGTERM signal or remove/unpause the paused links.
Result I expected:
INSTALLED
gets printed and the script exits.
The cause:
Object Manager is configured for Lua with the following:
wp_object_manager_request_object_features (om,
WP_TYPE_OBJECT, WP_OBJECT_FEATURES_ALL);
And that includes the feature WP_LINK_FEATURE_ESTABLISHED
for links, which waits until no links remain paused.
Possible solution:
Disable feature WP_LINK_FEATURE_ESTABLISHED
for type WP_TYPE_LINK
for Lua API with the following:
diff --git a/modules/module-lua-scripting/api/api.c b/modules/module-lua-scripting/api/api.c
index a3ab36ef..1ba10bc7 100644
--- a/modules/module-lua-scripting/api/api.c
+++ b/modules/module-lua-scripting/api/api.c
@@ -12,6 +12,7 @@
#include <pipewire/pipewire.h>
#include <wplua/wplua.h>
#include <libintl.h>
+#include <wp/link.h>
#define URI_API "resource:///org/freedesktop/pipewire/wireplumber/m-lua-scripting/api.lua"
@@ -758,6 +759,8 @@ object_manager_new (lua_State *L)
/* request all the features for Lua scripts to make their job easier */
wp_object_manager_request_object_features (om,
WP_TYPE_OBJECT, WP_OBJECT_FEATURES_ALL);
+ wp_object_manager_request_object_features (om,
+ WP_TYPE_LINK, WP_OBJECT_FEATURES_ALL & ~WP_LINK_FEATURE_ESTABLISHED);
return 1;
}