Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First socks request takes much more time when compared to other requests #39

Open
bokklu opened this issue May 24, 2020 · 0 comments
Open

Comments

@bokklu
Copy link

bokklu commented May 24, 2020

I've noticed that the first request always takes much more time when compared to the later requests of the same session. Below is the code to reproduce this behaviour:

async def connect_aiosocks(session, url):
    for i in range(10):
        try:
            start_time = time.time()
            async with async_timeout.timeout(7):
                async with session.get(url, proxy=f'socks4://72.11.148.222:56533') as response:
                    print(f'Request {i} {int(round((time.time() - start_time) * 1000))}ms')
        except asyncio.TimeoutError:
            continue
        except Exception as ex:
            print(ex)
            continue

async def fetch_aiosocks():
    conn = ProxyConnector(remote_resolve=False)
    async with aiohttp.ClientSession(connector=conn, request_class=ProxyClientRequest) as session:
        await connect_aiosocks(session, 'http://example.com')

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(fetch_aiosocks())

Output is the following:
image

Is this the intended behaviour?

I've tested this behaviour with the normal aiohttp library with http proxies, and it doesn't happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant