Fixes #4464: correct the logic for connection release and the logic to get the capabilities of the server