ceuk / spotui

Spotify in the terminal 💻🎶
MIT License
525 stars 22 forks source link

bugfix for searchdialog on main form breaking due to threading issue #20

Closed dbkosky closed 3 years ago

dbkosky commented 3 years ago

Hi ceuk. I've been looking at issue #14 today.

I've determined that this is happening as a result of a threading issue (which is part of the reason why it's occasional, and rather difficult to consistently reproduce the behavior).

I've found that the curses input is occasionally being run twice. First in the main thread, where it is supposed to, and unintentionally in the daemon status_loop thread. See bellow:

two_thread_inputs

What is presumably happening is that the condition not pause_updates is met in the status loop, a context switch happens, the main thread resumes, sets pause_updates to true, activates the search dialog, when the status_loop thread resumes (considering the condition has been met) it renders dialog again and thus two inputs are active.

satus_loop_show_search_bar

The fix might be what you want. I've tested it a bit and it seems to work OK. I've separated out the api call, since its non-critical and might take longer to run, from the thread lock section since it would likely inhibit performance.

ceuk commented 3 years ago

This seems to have fixed it - nice one!