Skip to content

[Improvement-18652][API] Make login session timeout configurable - #18653

Open
nanxiuzi wants to merge 3 commits into
apache:devfrom
nanxiuzi:improvement/session-timeout-configurable
Open

nanxiuzi wants to merge 3 commits into
apache:devfrom
nanxiuzi:improvement/session-timeout-configurable

Conversation

@nanxiuzi

Copy link
Copy Markdown
Contributor

Purpose of the pull request

Closes #18652.

The login session lifetime is hardcoded as Constants.SESSION_TIME_OUT = 7200, so operators cannot adjust it without patching the source and rebuilding. This PR moves it into ApiConfig and exposes it as api.session-timeout.

Brief change log

  • dolphinscheduler-api/.../api/configuration/ApiConfig.java
    • Add Duration sessionTimeout (default 2h), validate that it is positive, and log it in printConfig.
  • dolphinscheduler-api/.../api/service/impl/SessionServiceImpl.java
    • isSessionExpire reads apiConfig.getSessionTimeout() instead of the constant.
  • dolphinscheduler-common/.../common/constants/Constants.java
    • Remove the now-unused SESSION_TIME_OUT.
  • dolphinscheduler-api/src/main/resources/application.yaml, dolphinscheduler-standalone-server/src/main/resources/application.yaml
    • Document api.session-timeout.
  • Tests: SessionServiceTest gains an ApiConfig spy plus a case covering the configured timeout; LoginControllerTest derives the expired timestamp from the config.
  • Docs (en / zh): add the api.session-timeout row.

Root cause / motivation

Two problems with the constant approach:

  1. It is a static final int, so it is inlined into SessionServiceImpl at compile time. Editing the constant alone has no effect — dolphinscheduler-api must be recompiled as well.
  2. It lives in dolphinscheduler-common, which is a jar shared by master / worker / alert / tools. Changing it forces all of those services to be replaced for what is purely an API-server concern.

Behaviour

Unchanged by default: the field defaults to 2 hours, so deployments that do not set the property keep the current behaviour exactly.

Operators can now set, in api-server/conf/application.yaml:

api:
  session-timeout: 12h   # accepts a Duration, e.g. 30m, 2h, 1d

Verify this change

Unit tests pass:

Tests run: 18, Failures: 0, Errors: 0, Skipped: 0

The new case SessionServiceTest#testIsSessionExpireUsesConfiguredTimeout sets a 1-hour timeout and asserts a 30-minute-old session is alive while a 90-minute-old one has expired. Verified end-to-end on a 3.4.2 deployment: setting api.session-timeout: 12h keeps a session alive past the previous 2-hour limit, and the startup log shows the parsed value (API config: sessionTimeout -> PT12H).

Pull Request Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Improvement (enhancement to an existing feature)
  • Documentation update
  • Other (please describe):

Does this pull request potentially affect one of the following parts

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The core logic
  • The DSL
  • The RPC
  • The UI
  • The resources
  • The documentation
  • The configuration

AI usage disclosure

  • This contribution contains AI-generated code, and I have reviewed and tested it myself.
  • This contribution does not contain AI-generated code.

Checklist

  • I have read the CONTRIBUTING doc
  • I have added labels to this pull request
  • I have added the appropriate milestone to this pull request
  • I have associated a PR with an issue (required)
  • I have read the Code of Conduct

The session lifetime was a compile-time constant in the shared
dolphinscheduler-common module, which forced a rebuild and a replacement
of the jars consumed by master, worker and alert to change a setting that
only concerns the API server. Being a static final int, it was also
inlined into SessionServiceImpl, so editing the constant alone was not
enough.

Move it to ApiConfig as a Duration defaulting to 2h, keeping the existing
behaviour when the property is unset, and expose it as api.session-timeout
so operators can tune it from api-server/conf/application.yaml.

Expiry semantics are unchanged: the timeout is still measured from the
moment the user logs in.
@fuchanghai
fuchanghai force-pushed the improvement/session-timeout-configurable branch from db60fb3 to b428e2d Compare September 17, 2026 12:12
fuchanghai
fuchanghai previously approved these changes Sep 18, 2026

@fuchanghai fuchanghai left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if the CI pass

…out docs

The Chinese configuration table row added for api.session-timeout was not
padded to the flexmark-computed column width, so spotless:check failed and
took the Docs, Backend-Build and Build CI jobs down with it.
@SbloodyS SbloodyS added the improvement make more easy to user or prompt friendly label Sep 20, 2026
@SbloodyS SbloodyS added this to the 3.5.0 milestone Sep 20, 2026

@SbloodyS SbloodyS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the failed UT. @nanxiuzi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend document improvement make more easy to user or prompt friendly test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][API] Make login session timeout configurable

3 participants