Comments (6)
Hi @Ruwann ,
thanks for the quick response! Your suggestion did solve the problem!
from starlette.responses import StreamingResponse
# ...
async def streaming():
return StreamingResponse(async_gen_numbers(), status_code=200, media_type='text/plain')
from connexion.
Hi @mr-flannery ,
I'll have to look into the is_streamed
parameter, it seems that it is not correctly used.
In the meantime, can you try by using the underlying Starlette StreamingResponse
?
from connexion.
Hi @Ruwann ,
unfortunately, my response was a bit premature. It looks like it doesn't actually work as expected. While the code does run, it does not actually stream. From a caller's perspective it's still synchronous.
When calling the endpoint with curl, it still blocks for 10 seconds before anything happens, i.e.:
$ curl -N http://localhost:8080/streaming
# nothing happens for 10 seconds
0123456789
$
I wrote an Express app to make sure this was actually the server's fault, not curls:
const Express = require('express');
const app = new Express();
async function* generateNumbers() {
for (const i of [1, 2, 3, 4, 5]) {
await new Promise(resolve => setTimeout(resolve, 1000));
yield await Promise.resolve(i);
}
}
app.get('/streaming', async (req, res) => {
for await (const i of generateNumbers()) {
res.write(`data: ${i}\n\n`);
}
res.end();
});
app.listen(3456, () => {
console.log('Server is running on port 3456');
})
When using curl here, this works as expected, i.e. it sends a chunk of data every second.
Therefore, I believe there might actually be a bug with sending StreamingResponses in connexion3 + AsyncApp.
from connexion.
I cannot seem to reproduce the issue. When I use StreamingResponse
from starlette, the response is streamed to my terminal as expected.
I used the following sample code: https://github.com/Ruwann/connexion-streaming
from connexion.
Hi @Ruwann ,
thanks for the repo, I was able to track it down. This is what causes the behavior to change:
app.add_api("openapi.yaml", validate_responses=True)
Once I add validate_responses=True
to your code, it exhibits the same problem. Vice versa, if I remove it from my code, streaming works as expected.
from connexion.
Hi @Ruwann ,
just wanted to check in with you and see if there are there any plans to fix this?
Best regards!
from connexion.
Related Issues (20)
- AWS Lambda (and / or other cloud vendor) example(s) of Connexion 3 HOT 1
- `uvicorn.worker` for gunicorn is deprecated in favor of `uvicorn-worker` package
- Empty body parameter
- Is Connexion 3 Compatible with Flask-Limiter? Recommendations for Flask rate-limiting with Connexion 3.0? HOT 2
- Connexion v3, Flask v3 integration with dd-trace fails: datadog context not present in ASGI request scope, trace middleware may be missing HOT 1
- Documentation is misleading for `add_url_rule` when using AsyncApp
- Fix module name in running the app instructions in v3.rst HOT 2
- OperationId behaviour question
- [enhancement][docs] vscode launch.json example
- [enhancement][docs] aws lambda monolith (lambdalith)
- using validator DefaultsJSONRequestBodyValidator with more content-length breaks json data
- Failing to infer content when application/problem+json is present in another response code
- Upgrade dependencies (Flask)
- Test client failing to manage jwt security Unauthorized exceptions HOT 1
- How to resolve Connexion.FlaskAPP with ASGI server uvicorn / gunicorn has synchronous api calls Error: ERROR:root:error (0, '')
- [Question] Serving static files - AsyncApp
- MultiPartException('Missing boundary in multipart.') using test_client() on "multipart/form-data" API content
- Best way to modify Response body.
- Upgrade v2 dependencies to address recent security vulnerabilities like CVE-2024-34069 in werkzeug HOT 3
- URL containing new line character (%0A) causes an error 500
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connexion.