feat: refreshes the token and reconnects if publishing fails #228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a robust mechanism for proactively monitoring and refreshing JWT tokens used for Fleet MQTT connections. The changes add new configuration options, enhance token management, and implement background monitoring to ensure connections are refreshed before token expiry, reducing downtime and improving reliability.
Token expiry monitoring and proactive reconnection:
fleetConfigManagerto periodically check JWT token expiry and trigger reconnection before the token expires, using new configuration options for check interval and buffer (monitorTokenExpiry,TokenExpiryCheckInterval,TokenReconnectBuffer). [1] [2]reconnectChan) and supporting logic to handle reconnection requests triggered by token expiry or imminent expiry. [1] [2]Enhanced token management:
AuthTokenManagerto store credentials, refresh tokens using stored values, and accurately track token expiry using the JWTexpclaim with a safety buffer. Added methods for refreshing tokens, checking expiry, and extracting expiry time from JWTs. [1] [2] [3]Configuration and state improvements:
fleetConfigManagerto persist connection state, configuration, and backend information for use during reconnection events.Logging and diagnostics:
These changes collectively improve the agent's resilience to token expiry, reduce manual intervention, and provide better observability into token lifecycle events.