Skip to content

[Improvement-18699][API] Fix inverted session expiry check in createSessionIfAbsent - #18703

Open
kittimzhe wants to merge 2 commits into
apache:devfrom
kittimzhe:session-expiry-inversion-18699
Open

kittimzhe wants to merge 2 commits into
apache:devfrom
kittimzhe:session-expiry-inversion-18699

Conversation

@kittimzhe

Copy link
Copy Markdown
Contributor

Was this PR generated or assisted by AI?

YES — issue triage, root-cause analysis, fix and tests were developed with AI assistance (mechanism verified against the code and pinned by red→green tests below).

Purpose of the pull request

Fixes #18699. SessionServiceImpl#createSessionIfAbsent reused an expired session (refreshing its last-login time) and deleted a still-valid one — the exact opposite of the method's contract. A second successful login invalidated the user's live session, while a timed-out session ID was kept alive.

Brief change log

  • Invert the branch in createSessionIfAbsent: reuse the existing session when !isSessionExpire(session), delete-and-recreate when it has expired.

Regression origin (answering the question in the issue): commit 12f8138 (#15219, "Expire session when update user password") rewrote the old createSession into createSessionIfAbsent and flipped the polarity along the way — the pre-refactor code reused the session when now - lastLoginTime <= SESSION_TIME_OUT (i.e. not expired). So this is a regression introduced in #15219, not an intentional login policy.

Verify this pull request

This change added tests and can be verified as follows:

  • SessionServiceTest#testCreateSessionIfAbsentReusesUnexpiredSession — an unexpired session is returned as-is (updateById called; no deleteById/insert). Fails on the pre-fix code (expected the old session id but got a freshly generated UUID).
  • SessionServiceTest#testCreateSessionIfAbsentReplacesExpiredSession — a session 40 days past its last login is deleted and a new one inserted. Fails on the pre-fix code (the expired id was returned).
  • Full SessionServiceTest: 6/6 green with the fix (JDK 8, mvn test -pl dolphinscheduler-api -Dtest=SessionServiceTest).

@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 follow the pull reuqest notice.

…Absent

Reuse the existing session when it is still valid and replace it when it
has expired — the previous condition did the opposite, so a second
successful login deleted the user's live session (killing their other
tab/devices) while a timed-out session was refreshed and reused.
@kittimzhe
kittimzhe force-pushed the session-expiry-inversion-18699 branch from bbe2b54 to 86a1226 Compare October 14, 2026 03:59
@kittimzhe kittimzhe changed the title [Bug-18699][API] Fix inverted session expiry check in createSessionIfAbsent [Fix-18699][API] Fix inverted session expiry check in createSessionIfAbsent Oct 14, 2026
@kittimzhe

Copy link
Copy Markdown
Contributor Author

Thanks for the gate check — fixed per the Pull Request Notice:

  • PR title: [Bug-…] → [Fix-18699][API] (Bug issue → Fix type)
  • Commit message: amended to the same [Fix-18699][API] format
  • Spotless: mvn spotless:check clean on the touched modules (dolphinscheduler-api, dolphinscheduler-common, dolphinscheduler-task-http)

The issue triage, root-cause analysis, fix and tests are unchanged.

@SbloodyS SbloodyS changed the title [Fix-18699][API] Fix inverted session expiry check in createSessionIfAbsent [Improvement-18699][API] Fix inverted session expiry check in createSessionIfAbsent Oct 14, 2026
@SbloodyS SbloodyS added the improvement make more easy to user or prompt friendly label Oct 14, 2026
@SbloodyS SbloodyS added this to the 3.5.0 milestone Oct 14, 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.

Remove useless comment.

}
session = sessionList.get(0);
if (isSessionExpire(session)) {
// An unexpired session is reused (its last-login time refreshed); an

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.

Suggested change
// An unexpired session is reused (its last-login time refreshed); an

session = sessionList.get(0);
if (isSessionExpire(session)) {
// An unexpired session is reused (its last-login time refreshed); an
// expired one is deleted so a new session is created below

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.

Suggested change
// expired one is deleted so a new session is created below

Comment on lines +123 to +126
/**
* #18699: an unexpired session must be reused on re-login, not deleted and
* replaced (the expired/unexpired branches were inverted before the fix)
*/

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.

Suggested change
/**
* #18699: an unexpired session must be reused on re-login, not deleted and
* replaced (the expired/unexpired branches were inverted before the fix)
*/

Comment on lines +144 to +148
/**
* #18699: an expired session must be replaced by a new one on re-login,
* not refreshed and reused (the expired/unexpired branches were inverted
* before the fix)
*/

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.

Suggested change
/**
* #18699: an expired session must be replaced by a new one on re-login,
* not refreshed and reused (the expired/unexpired branches were inverted
* before the fix)
*/

This branch has not been deployed

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

Labels

backend 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] Suspected inverted session expiry check invalidates active sessions on re-login

2 participants