Release api lock on connection close or finish

fix #4372
Merge branch 'develop'