Replace the ConnectionManagement middleware with new middleware, fixes #1749