Title: Server.wait_closed() doesn't always wait for its transports to fihish
Type: Stage:
Components: asyncio Versions: Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, aymeric.augustin, yselivanov
Priority: normal Keywords:

Created on 2018-06-01 05:11 by yselivanov, last changed 2018-09-30 13:50 by aymeric.augustin.

Messages (2)
msg318360 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-01 05:11
Server.wait_closed() currently does two checks:

1. if _sockets is None -- means that Server.close() was called
2. if self._waiters is None -- means that Server._wakeup() was called

if (1) *or* (2) is true, wait_closed() just returns without waiting on anything.

However, when Server.close() is called there might be still active transports serving requests.  Server.wait_closed() should wait until all of them are detached, even if Server._sockets is already reset.

So the below implementation:

    async def wait_closed(self):
        if self._sockets is None or self._waiters is None:
        waiter = self._loop.create_future()
        await waiter

should be changed to:

    async def wait_closed(self):
        if self._waiters is None:
            assert self._active_count == 0
        waiter = self._loop.create_future()
        await waiter
msg326724 - (view) Author: Aymeric Augustin (aymeric.augustin) * Date: 2018-09-30 13:50
I believe this is by design: the documentation says:

> The sockets that represent existing incoming client connections are left open.

`Server` doesn't keep track of active transports serving requests.

(That said, I haven't figured out what _waiters is here so I could be wrong.)
Date User Action Args
2018-09-30 13:50:09aymeric.augustinsetnosy: + aymeric.augustin
messages: + msg326724
2018-06-01 05:11:49yselivanovcreate