# Buggy code
async def run_background_asyncio_services(services: Sequence[ServiceAPI]) -> None:
    await _run_background_services(services, background_asyncio_service)


# Traceback (combined_error)
Traceback (most recent call last):
File "/usr/src/app/trinity/trinity/extensibility/trio.py", line 50, in run_process
await self.do_run(event_bus)
File "/usr/src/app/trinity/trinity/components/builtin/metrics/component.py", line 171, in do_run
await managers[0].wait_finished()
File "/usr/local/lib/python3.7/contextlib.py", line 678, in __aexit__
raise exc_details[1]
File "/usr/local/lib/python3.7/contextlib.py", line 661, in __aexit__
cb_suppress = await cb(*exc_details)
File "/usr/local/lib/python3.7/contextlib.py", line 552, in _exit_wrapper
return await cm_exit(cm, exc_type, exc, tb)
File "/usr/local/lib/python3.7/site-packages/async_generator/_util.py", line 53, in __aexit__
await self._agen.athrow(type, value, traceback)
File "/usr/local/lib/python3.7/site-packages/async_service/trio.py", line 411, in background_trio_service
await manager.stop()
File "/usr/local/lib/python3.7/site-packages/trio/_core/_run.py", line 730, in __aexit__
raise combined_error_from_nursery
File "/usr/local/lib/python3.7/site-packages/async_service/trio.py", line 208, in run
for _, exc_value, exc_tb in self._errors
File "/usr/local/lib/python3.7/site-packages/async_service/base.py", line 300, in _run_and_manage_task
await task.run()
File "/usr/local/lib/python3.7/site-packages/async_service/trio.py", line 76, in run
await self._async_fn(*self._async_fn_args)
File "/usr/src/app/trinity/trinity/components/builtin/metrics/service/trio.py", line 10, in continuously_report
self._reporter.report_now()
File "/usr/local/lib/python3.7/site-packages/pyformance/reporters/influx.py", line 88, in report_now
response = urlopen(request)
File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/local/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.7/urllib/request.py", line 1345, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/local/lib/python3.7/urllib/request.py", line 1320, in do_open
r = h.getresponse()
File "/usr/local/lib/python3.7/http/client.py", line 1336, in getresponse
response.begin()
File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

# Fixed code
async def run_background_asyncio_services(services: Sequence[ServiceAPI]) -> None:
    async with contextlib.AsyncExitStack() as stack:
        managers = tuple(
            [
                await stack.enter_async_context(background_asyncio_service(service))
                for service in services
            ]
        )
        # If any of the services terminate, we do so as well.
        await wait_first_asyncio(
            [asyncio.create_task(manager.wait_finished()) for manager in managers]
        )