I have a Flask route that returns deterministic responses when run with a single thread (either in development mode or in production with gunicorn -w 1, but behaves non-deterministically when run with more gunicorn workers e.g. gunicorn -w 3.
After calling e.g. GET /do_something/hello once and getting a 200, when I call GET /do_something/hello again I sometimes get a 422, while at other times I get a 500.
Both tracker and recording whether 'foo' has been processed are done using Redis.
@flask_app.route('/do_something/<string:foo>')
def do_something(foo: str):
if tracker.seen(foo):
return 'Foo already seen', 422
try:
// Do something
// *** Record that 'foo' has already been processed ***
// There is another check here which throws a ValueError if 'foo' has already been
// processed.
return 'Done'
except ValueError:
return 'Error during processing!', 500