locks moved to outside of try block for fixing issues #3090 and #3091