(self)
| 179 | self.proxy._close_connection(self) |
| 180 | |
| 181 | async def handle(self): |
| 182 | self.proxy_to_backend_task = asyncio.ensure_future( |
| 183 | self.proxy_to_backend()) |
| 184 | |
| 185 | self.proxy_from_backend_task = asyncio.ensure_future( |
| 186 | self.proxy_from_backend()) |
| 187 | |
| 188 | try: |
| 189 | await asyncio.wait( |
| 190 | [self.proxy_to_backend_task, self.proxy_from_backend_task], |
| 191 | return_when=asyncio.FIRST_COMPLETED) |
| 192 | |
| 193 | finally: |
| 194 | if self.proxy_to_backend_task is not None: |
| 195 | self.proxy_to_backend_task.cancel() |
| 196 | |
| 197 | if self.proxy_from_backend_task is not None: |
| 198 | self.proxy_from_backend_task.cancel() |
| 199 | |
| 200 | # Asyncio fails to properly remove the readers and writers |
| 201 | # when the task doing recv() or send() is cancelled, so |
| 202 | # we must remove the readers and writers manually before |
| 203 | # closing the sockets. |
| 204 | self.loop.remove_reader(self.client_sock.fileno()) |
| 205 | self.loop.remove_writer(self.client_sock.fileno()) |
| 206 | self.loop.remove_reader(self.backend_sock.fileno()) |
| 207 | self.loop.remove_writer(self.backend_sock.fileno()) |
| 208 | |
| 209 | self.client_sock.close() |
| 210 | self.backend_sock.close() |
| 211 | |
| 212 | async def _read(self, sock, n): |
| 213 | read_task = asyncio.ensure_future( |
no test coverage detected