jcorporation/myMPD

2 MPD Player triggers with API calls: possible lock or race condition

Closed this issue · 5 comments

myMPD version: 16.0.1

Describe the bug

I have two scripts as MPD Player triggers, both use mympd.init() and some API calls. Almost on every song start one of these scripts fails with error: Unknown error: No API response, timeout after 60s. If I add 1 second delay at beginning of either script this error disappears.

Debug logs
error.log

It should be completely async. I dig into this.

I can not reproduce your issue. I used following script:

mympd.init()
mympd.log(4, "Skript " .. mympd_arguments.nr)
return "Skript " .. mympd_arguments.nr

However I added some code in devel that could fix your issue.

Yes, with two scripts/triggers, containing only mympd.init() and one api call mympd.api("MYMPD_API_PLAYER_CURRENT_SONG") there is no error. Here are my 2 simple scripts, with which I can reproduce error:

test_init_1.lua:

-- {"order":1,"file":"","version":0,"arguments":["trigger"]}
print("test_init_1 begin")

mympd.init()

local play_state = mympd_state.play_state
local elapsed_time = mympd_state.elapsed_time

if play_state ~= 2 or elapsed_time > 5 then
  print("test_init_1 not playing")
  return "test_init_1 not playing"
end

local rc, result = mympd.api("MYMPD_API_PLAYER_CURRENT_SONG")
if rc ~= 0 then
 print("test_init_1 current song error")
 return "test_init_1 current song error"
end

print("test_init_1", result.uri)

print("test_init_1 end")

return "test_init_1 return"

test_init_2.lua:

-- {"order":1,"file":"","version":0,"arguments":["trigger"]}
print("test_init_2 begin")

function mympd_set_variable(p_key, p_value)
  print("mympd_set_variable " .. p_key .. "=" .. p_value)
  mympd.api("MYMPD_API_SCRIPT_VAR_SET", { key = p_key, value = tostring(p_value) })
end

mympd.init()

local play_state = mympd_state.play_state
local elapsed_time = mympd_state.elapsed_time
local song_pos = mympd_state.song_pos

if play_state ~= 2 or elapsed_time > 5 then
  print("test_init_2 not playing")
  return "test_init_2 not playing"
end

if play_state == 2 and song_pos > 0 and mympd_env.var_playlist_current_playlist then
  print("playing stored playlist " .. song_pos)
  mympd_set_variable("test", song_pos)
end

print("test_init_2 end")

return "test_init_2 return"

of course assuming that mympd_env.var_playlist_current_playlist exists
then script 1 ends with error

I will try devel branch a bit later

I confirm, on devel branch there is no error with my test scripts and with my real scripts
no_error.log

Great!