aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

aiohttp.client_exceptions.ClientOSError: [Errno 32] Broken pipe

Open openspeedtest opened this issue 3 years ago • 0 comments

Describe the bug

import asyncio
import io
import os

import aiohttp
from tqdm.asyncio import tqdm


URL = 'http://your-ip:3000/upload'


async def chunks(data, chunk_size):
    with tqdm.wrapattr(io.BytesIO(data), 'read', total=len(data)) as f:
        chunk = f.read(chunk_size)
        while chunk:
            yield chunk
            chunk = f.read(chunk_size)


async def download(session, chunk_size):
    data_to_send = os.urandom(30_000_000)
    data_generator = chunks(data_to_send, chunk_size)
    await session.post(URL, data=data_generator)

        
async def main():
    async with aiohttp.ClientSession() as session:
        tasks = [] 
        for _ in range(5):
            t = asyncio.create_task(download(session, 4096))
            tasks.append(t)
        await asyncio.gather(*tasks)
            

asyncio.run(main())

I am trying to make a CLI client for OpenSpeedTest-Server I am getting same error like this. to reproduce this use our DOCKER IMAGE or Android App. then make a post request to "http://your-ip:3000/upload" issues : For docker image it will only send first chunk for Android app it will throw error like this.

Traceback (most recent call last):
  File "r.py", line 35, in <module>
    asyncio.run(main())
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "r.py", line 32, in main
    await asyncio.gather(*tasks)
  File "r.py", line 23, in download
    await session.post(URL, data=data_generator)
  File "/Users/goredplanet/Library/Python/3.8/lib/python/site-packages/aiohttp/client.py", line 559, in _request
    await resp.start(conn)
  File "/Users/goredplanet/Library/Python/3.8/lib/python/site-packages/aiohttp/client_reqrep.py", line 898, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "/Users/goredplanet/Library/Python/3.8/lib/python/site-packages/aiohttp/streams.py", line 616, in read
    await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 32] Broken pipe

It is working fine when using Electron Apps of OpenSpeedTest-Server (Windows, Mac and Linux GUI Server apps) it uses Express server.

Mobile Apps uses iOnic WebServer, for Android it's NanoHTTP Server and for iOS it is GDC WebServer. for Docker we use Nginx WebServer. Configuration posted on my profile.

To Reproduce

  1. Download OpenSpeedTest-Server Android App 2)Run script i posted after changing the IP address to the one shown in the app. 3)Make sure you are making a POST request to http://your-ip/upload
  2. Error

Expected behavior

If you run the same script on GUI OpenSpeedTest -Server (Electron Apps) Upload finishes without issue.

Logs/tracebacks

`
Traceback (most recent call last):
  File "r.py", line 35, in <module>
    asyncio.run(main())
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "r.py", line 32, in main
    await asyncio.gather(*tasks)
  File "r.py", line 23, in download
    await session.post(URL, data=data_generator)
  File "/Users/goredplanet/Library/Python/3.8/lib/python/site-packages/aiohttp/client.py", line 559, in _request
    await resp.start(conn)
  File "/Users/goredplanet/Library/Python/3.8/lib/python/site-packages/aiohttp/client_reqrep.py", line 898, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "/Users/goredplanet/Library/Python/3.8/lib/python/site-packages/aiohttp/streams.py", line 616, in read
    await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 32] Broken pipe


### Python Version

```console
Python 3.8.9

aiohttp Version

Name: aiohttp
Version: 3.8.1

multidict Version

Name: multidict
Version: 6.0.2

yarl Version

Name: yarl
Version: 1.8.1

OS

MacOS 12.5.1 (21G83)

Related component

Client

Additional context

This is a CLI-Client

Code of Conduct

  • [X] I agree to follow the aio-libs Code of Conduct

openspeedtest avatar Sep 09 '22 06:09 openspeedtest