Skip to content

SSL with closed connections #3052

Closed
@Usever

Description

Long story short

Receiving strange errors when bots are connecting to my SSL (HTTPS) server without sending any data and disconnecting afterwards.
SSL protocol handler inside aiohttp shows unexpected errors. This never happens to plain HTTP connections.

Expected behaviour

No messages received (as for HTTP protocol).

Actual behaviour

Multiple errors:
task: <Task pending coro=<RequestHandler.start() done, defined at C:\Program Files\Python36\lib\site-packages\aiohttp\web_protocol.py:342> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000001E0FBF59D98>()]>>
Task was destroyed but it is pending!

Steps to reproduce

Run simple example:

import asyncio  
import aiohttp.web
import ssl

async def fetch_page():
    while True:
        reader, writer = await asyncio.open_connection('127.0.0.1', 443)
        writer.close()
    
async def request_handler(request: aiohttp.web.BaseRequest):
    await request.read()
    return aiohttp.web.Response(status=200, content_type='text/html')

async def start_server():
    ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    ssl_context.check_hostname = False
    ssl_context.load_cert_chain('any.crt', 'any.key')

    server = aiohttp.web.Server(request_handler)
    await loop.create_server(server, '127.0.0.1', 443, ssl=ssl_context) # removing ssl=ssl_context disables SSL and fixes the bug
    await fetch_page()

if __name__ == '__main__':  
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.gather(asyncio.Task(start_server())))

Your environment

Checked both Windows 10 and CentOS 7, aiohttp 3.0.4 and 3.3.0

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions