Fix dead locks caused by commands with CS on http listener threads and CS on main thread + CS on other threads

Closes #2041

Edited by Razvan Becheriu

Merge request reports