# Buggy code
async def _get_services(self, host: IPv4Address, timeout: int):
    port = int(os.environ.get("PYATV_UDNS_PORT", 5353))  # For testing purposes
    services = [s[0:-1] for s in ALL_SERVICES]
    try:
        await knock.knock(host, KNOCK_PORTS, self.loop)
        response = await udns.request(
            self.loop, str(host), services, port=port, timeout=timeout
        )
    except asyncio.TimeoutError:
        response = None
    return host, response


# Traceback (asyncio.TimeoutError)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/__main__.py", line 565, in _run_application
return await cli_handler(loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/__main__.py", line 388, in cli_handler
return await _handle_commands(args, config, loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/__main__.py", line 480, in _handle_commands
ret = await _handle_device_command(args, cmd, atv, loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/__main__.py", line 517, in _handle_device_command
return (await _exec_command(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/__main__.py", line 531, in _exec_command
value = await tmp(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/airplay/__init__.py", line 71, in play_url
player = await self._player(session)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/airplay/__init__.py", line 51, in _player
await verifier.verify_authed()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 88, in verify_authed
resp = await self._send(self.srp.verify1(), 'verify1')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 100, in _send
resp, code = await self.http.post_data(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/net.py", line 76, in post_data
raise ex
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/net.py", line 64, in post_data
resp = await self._session.post(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aiohttp/client.py", line 504, in _request
await resp.start(conn)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 860, in start
self._continue = None
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aiohttp/helpers.py", line 596, in __exit__
raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

# Fixed code
async def _get_services(self, host: IPv4Address, timeout: int):
    port = int(os.environ.get("PYATV_UDNS_PORT", 5353))  # For testing purposes
    services = [s[0:-1] for s in ALL_SERVICES]
    knocker = None
    try:
        knocker = await knock.knocker(host, KNOCK_PORTS, self.loop, timeout=timeout)
        response = await udns.request(
            self.loop, str(host), services, port=port, timeout=timeout
        )
    except asyncio.TimeoutError:
        response = None
    finally:
        if knocker:
            knocker.cancel()
    return host, response