Skip to content

Release a suspended non-transactional Session - #37715

Closed
iyuan7 wants to merge 1 commit into
spring-projects:mainfrom
iyuan7:release-suspended-session-connection
Closed

iyuan7 wants to merge 1 commit into
spring-projects:mainfrom
iyuan7:release-suspended-session-connection

Conversation

@iyuan7

@iyuan7 iyuan7 commented Nov 18, 2026

Copy link
Copy Markdown

A Session opened by SpringSessionContext for PROPAGATION_NEVER, or for PROPAGATION_SUPPORTS without an existing transaction, was given a connection from DataSourceUtils. That connection stayed borrowed while the scope was suspended, so a nested PROPAGATION_REQUIRED transaction needed a second pooled connection.

The non-transactional Session is now opened without a Spring-supplied connection, and Hibernate releases it on suspend. A connection supplied for a real transaction is left alone: manualDisconnect() drops it without returning it to the pool, and resume does not reconnect.

Fixes gh-37706

Test plan

  • NEVER and SUPPORTS borrow at most one connection across the nested transaction
  • A pool of size 1 completes the nested transaction
  • The outer Session can query again after the nested transaction commits
  • SUPPORTS inside an existing transaction still uses that transaction's connection

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 18, 2026
A Session opened for PROPAGATION_NEVER or PROPAGATION_SUPPORTS
without a real transaction kept a pooled connection while
suspended. Open that Session without a Spring-supplied
connection, and disconnect only Hibernate-managed connections.

Fixes spring-projectsgh-37706

Signed-off-by: iyuan7 <mryuanvip@163.com>
@iyuan7
iyuan7 force-pushed the release-suspended-session-connection branch from afdf769 to 09037a8 Compare November 19, 2026 06:55
@jhoeller

Copy link
Copy Markdown
Contributor

As per my explanation in #37706 (comment), we do not intend to optimize for such SUPPORTS->REQUIRED style nesting but rather for actual transaction nesting.

Note that the orginal issue had not been triaged. Please refrain from opening PRs before we had a chance to triage the issue.

@jhoeller jhoeller closed this Nov 19, 2026
@jhoeller jhoeller added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

3 participants