Merge branch 'MDL-49740-locking-bugs' of https://github.com/brendanheywood/moodle