Skip to content

fix auto_relogin getting stuck without a token after a failed re-login - #86

Open
DanyGoT wants to merge 1 commit into
davidhamann:masterfrom
DanyGoT:fix/auto-relogin-failed-login
Open

DanyGoT wants to merge 1 commit into
davidhamann:masterfrom
DanyGoT:fix/auto-relogin-failed-login

Conversation

@DanyGoT

@DanyGoT DanyGoT commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

This happened to us in production, so I made a fix.

For context, we use a single shared Server object for the whole app and rely only on auto_relogin to keep the session alive. We never call login() manually after startup.

When a request gets a 952 (invalid token), auto_relogin sets _token to None and calls login(). If that login throws (in our case most likely FileMaker Server being briefly unreachable), the token is never set again. From then on every request is sent without an Authorization header, and FileMaker returns:

FileMaker Server returned error 10, Request validation failed: Parameter (Authorization) is required

auto_relogin only reacts to 952, so it never tries again, and the server object stays broken until the process is restarted.

This fix keeps track of whether a relogin is still pending. If the last relogin failed, the next request tries to log in again before it's sent. The flag is cleared on a successful login, so an explicit logout() is not undone by auto_relogin. I also added a unit test for the failed relogin case.

Alternatively, _with_auto_relogin could also relog on error 10 when there's no token:

if (self.last_error == FMSErrorCode.INVALID_DAPI_TOKEN.value
        or (self.last_error == FMSErrorCode.MISSING_DATA.value and not self._token)):

That needs MISSING_DATA = 10 added to FMSErrorCode. It's simpler, but it costs one failed request first and would undo an explicit logout().

@DanyGoT

DanyGoT commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Forgot to make an issue

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

Successfully merging this pull request may close these issues.

1 participant