Fief responds with "500 Internal Server Error" while using different Admin REST API from a script.
Steps to reproduce the behavior:
No "500 Internal server error" responses from Fief.
self-hosted, Fief version: 0.24.2
The error is non-deterministic, it's not related to any particular request, any request can return 500.
When I added 1 second delay between requests, everything went OK. You can see the successful log below.
xxx@xxx:/opt/src# fief run-server --port 8001 2>&1
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Main Fief workspace already exists
Main Fief user already exists
2023-05-02 15:08:24.725 | INFO | fief.lifespan:lifespan:31 - Fief Server started - {"version": "0.24.2"}
INFO: 127.0.0.1:50620 - "GET /tenants/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:50630 - "POST /permissions/ HTTP/1.1" 201 Created
2023-05-02 15:08:31.188 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:08:31.274 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
INFO: 127.0.0.1:50632 - "POST /permissions/ HTTP/1.1" 201 Created
2023-05-02 15:08:31.636 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:08:31.647 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
INFO: 127.0.0.1:50644 - "POST /users/ HTTP/1.1" 201 Created
2023-05-02 15:08:32.796 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "on_after_register"}
2023-05-02 15:08:32.871 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "on_after_register"}
2023-05-02 15:08:32.877 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:08:32.889 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
INFO: 127.0.0.1:50650 - "POST /users/ HTTP/1.1" 201 Created
2023-05-02 15:08:33.847 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "on_after_register"}
2023-05-02 15:08:33.900 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "on_after_register"}
2023-05-02 15:08:33.921 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:08:33.936 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
INFO: 127.0.0.1:50662 - "POST /users/40284c05-9b18-431d-a2ef-b9f1707d76d3/permissions HTTP/1.1" 201 Created
2023-05-02 15:08:34.871 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:08:34.886 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
INFO: 127.0.0.1:50668 - "POST /users/90e4cecd-7898-43a3-84d6-feacdeebaab6/permissions HTTP/1.1" 201 Created
2023-05-02 15:08:35.884 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:08:35.912 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
^C
Without delays, however, I could not execute my script fully, not getting 500 at some of the requests. The log in this case looks like this:
xxx@xxx:/opt/src# fief run-server --port 8001 2>&1
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Main Fief workspace already exists
Main Fief user already exists
2023-05-02 15:12:02.562 | INFO | fief.lifespan:lifespan:31 - Fief Server started - {"version": "0.24.2"}
INFO: 127.0.0.1:60742 - "GET /tenants/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:52424 - "POST /permissions/ HTTP/1.1" 201 Created
INFO: 127.0.0.1:52434 - "POST /permissions/ HTTP/1.1" 201 Created
INFO: 127.0.0.1:52450 - "POST /users/ HTTP/1.1" 201 Created
2023-05-02 15:12:08.245 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
INFO: 127.0.0.1:52456 - "POST /users/ HTTP/1.1" 500 Internal Server Error
2023-05-02 15:12:08.344 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
2023-05-02 15:12:08.351 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:12:08.381 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
2023-05-02 15:12:08.402 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:12:08.437 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
2023-05-02 15:12:08.443 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "on_after_register"}
2023-05-02 15:12:08.519 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "on_after_register"}
^C
xxx@xxx:/opt/src# fief run-server --port 8001 2>&1
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Main Fief workspace already exists
Main Fief user already exists
2023-05-02 15:36:08.331 | INFO | fief.lifespan:lifespan:31 - Fief Server started - {"version": "0.24.2"}
INFO: 127.0.0.1:44862 - "GET /tenants/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:44870 - "POST /permissions/ HTTP/1.1" 201 Created
INFO: 127.0.0.1:44874 - "POST /permissions/ HTTP/1.1" 500 Internal Server Error
2023-05-02 15:36:12.437 | INFO | fief.tasks.base:__call__:117 - Start task - {"task": "trigger_webhooks"}
2023-05-02 15:36:12.511 | INFO | fief.tasks.base:__call__:119 - Done task - {"task": "trigger_webhooks"}
^C
It looks like, there is a race related to webhooks somewhere.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too