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

How to resolve Connexion.FlaskAPP with ASGI server uvicorn / gunicorn has synchronous api calls Error: ERROR:root:error (0, '') #1962

Open
karthikc08 opened this issue Aug 9, 2024 Discussed in #1961 · 0 comments

Comments

@karthikc08
Copy link

Discussed in #1961

Originally posted by karthikc08 August 9, 2024
After migrating from connexion2 to connexion 3 we are facing a weird error causing the application to stop.
When ever multiple api calls are triggered from application to Flask app server with ASGI it randomly throws unauthorized error stating: ERROR:root:error (0, '')

When a single call is made it works but when multiple api calls are triggered from a single promise or one after other application randomly returns result once and throws 401 error some times.

Trace logs:

TRACE:    127.0.0.1:53718 - ASGI [7] Started scope={'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.1', 'server': ('127.0.0.1', 8080), 'client': ('127.0.0.1', 53718), 'scheme': 'http', 'root_path': '', 'headers': '<...>', 'state': {}, 'method': 'GET', 'path': '/api/v1/me/offers', 'raw_path': b'/api/v1/me/offers', 'query_string': b''}
TRACE:    127.0.0.1:53685 - ASGI [6] Send {'type': 'http.response.start', 'status': 401, 'headers': '<...>'}
TRACE:    127.0.0.1:53718 - ASGI [7] Send {'type': 'http.response.start', 'status': 401, 'headers': '<...>'}
TRACE:    127.0.0.1:53685 - ASGI [6] Send {'type': 'http.response.body', 'body': '<90 bytes>', 'more_body': True}
TRACE:    127.0.0.1:53718 - ASGI [7] Send {'type': 'http.response.body', 'body': '<90 bytes>', 'more_body': True}
TRACE:    127.0.0.1:53685 - ASGI [6] Send {'type': 'http.response.body', 'body': '<0 bytes>'}
TRACE:    127.0.0.1:53718 - ASGI [7] Send {'type': 'http.response.body', 'body': '<0 bytes>'}
TRACE:    127.0.0.1:53685 - ASGI [6] Completed
TRACE:    127.0.0.1:53718 - ASGI [7] Completed
ERROR:root:error (0, '')
ERROR:root:error (0, '')
INFO:     127.0.0.1:53685 - "GET /api/v1/me HTTP/1.1" 401 Unauthorized
INFO:     127.0.0.1:53718 - "GET /api/v1/me/offers HTTP/1.1" 401 Unauthorized
TRACE:    127.0.0.1:53685 - HTTP connection lost
TRACE:    127.0.0.1:53718 - HTTP connection lost

Posted the issue on stack overflow too: https://stackoverflow.com/questions/78849875/running-flask-app-with-connexion-3-1-0-with-synchronous-api-calls

Code used:

app = connexion.FlaskApp(__name__, specification_dir='config/swagger/')
CORS(app.app, supports_credentials=True)
app.add_middleware(
      CORSMiddleware,
      position=MiddlewarePosition.BEFORE_EXCEPTION,
      allow_origins=["*"],
      allow_credentials=True,
      allow_methods=["*"],
      allow_headers=["*"],
)

@app.app.after_request
def cache_busting_headers(response):
    response.headers.extend({
        'Last-Modified': datetime.now(),
        'Cache-Control': cache_control_header,
        'Pragma': 'no-cache',
        'Expires': '0'
    })
    return response

def run():
    uvicorn.run(app, port=int(os.getenv('PORT', 8080)), log_level='trace')


if __name__ == '__main__':
    run()

Dependencies used:
connexion[flask,uvicorn,swagger-ui]==3.1.0 Flask-Cors==4.0.1

Can anyone guide me on the solution for this.

@karthikc08 karthikc08 changed the title How to resolve Connexion.FlaskAPP with ASGI server uvicorn / gunicorn has synchronous api calls Errors. How to resolve Connexion.FlaskAPP with ASGI server uvicorn / gunicorn has synchronous api calls Error: ERROR:root:error (0, '') Aug 9, 2024
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