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

Wrong response for simultaneous requests with a long processing time #7635

Open
1 task done
ulysses500 opened this issue Sep 29, 2023 · 4 comments
Open
1 task done
Labels
bug needs-info Issue is lacking sufficient information and will be closed if not provided

Comments

@ulysses500
Copy link

ulysses500 commented Sep 29, 2023

Describe the bug

I have a bug where two separate requests, a few seconds apart, consistently receive the response from the first request. Here is the client-side request:

async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=1200)) as aiohttp_session:
    PS_extension = "/" + str(random.randint(1, 1000000))
                        headers = {
                        'Cache-Control': 'no-cache'
                    }
    async with aiohttp_session.post(PS_URL + "/task_execution" + PS_extension,
                                    data=pp_data, timeout=1200, headers=headers) as aiohttp_response:

And this is the custom server-side endpoint with FastAPI:

@app.post('/task_execution/{random_number}')
async def task_execution(request: Request, random_number):
                        headers = { 'Cache-Control': 'no-cache'  }
                    
                    ...

                return Response(content= json_data, headers=headers)
                    
                    

Unfortunatelly, the response is not specific to the request, even if there is a random number. It's worth noting that the response takes a long time due to a lengthy Deep Learning generation process (30 seconds to 1 minute), so it's not a latency or performance issue.

To Reproduce

  1. Send 2 simultaneous requests with json data from 2 different devices
  2. Wait 30 seconds to 1 minute
  3. Both devices receive the first answer

Expected behavior

Every request should have its corresponding answer.

Logs/tracebacks

None.

Python Version

$ python --version
3.9

aiohttp Version

$ python -m pip show aiohttp
Version: 3.8.3

multidict Version

$ python -m pip show multidict
Version: 6.0.4

yarl Version

$ python -m pip show yarl
Version: 1.8.2

OS

Windows 11

Related component

Server, Client

Additional context

Google App Engine

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@ulysses500 ulysses500 added the bug label Sep 29, 2023
@Dreamsorcerer
Copy link
Member

You'll need to create a full reproducer, it seems incredibly unlikely that this is an issue with aiohttp, as it seems like it'd affect 1000s of users if that was really happening.

@ulysses500
Copy link
Author

ulysses500 commented Sep 29, 2023

You are right.
I have noticed that I have made a mistake in FastAPI, in the main function that calls aiohttp:

@app.get('/get_data/{random_ref}')
   async def get_data(request: Request):

instead of:

@app.get('/get_data/{random_ref}')
    async def get_data(request: Request,random_ref):

It could have mistaken the main request and not the one from aiohttp.

@ulysses500
Copy link
Author

ulysses500 commented Sep 29, 2023

The problem still happens. Could be a problem from FastAPI.

Note: Not sure that many aiohttp users have long processes to deal with.

@Dreamsorcerer
Copy link
Member

It still looks very unlikely to be an issue with aiohttp. I just can't imagine how 2 requests could resolve the same response, they have separate connections and are isolated objects. Unless you can reproduce this with an aiohttp server, I feel like this is an issue with FastAPI (or your code).

@Dreamsorcerer Dreamsorcerer added the needs-info Issue is lacking sufficient information and will be closed if not provided label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-info Issue is lacking sufficient information and will be closed if not provided
Projects
None yet
Development

No branches or pull requests

2 participants