Skip to content

Fix BZ 70370 - Make the JDBC 4.3 request boundary hints opt-in - #1268

Closed
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:bz70370-request-hints
Closed

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:bz70370-request-hints

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

https://bz.apache.org/bugzilla/show_bug.cgi?id=70370

Since 11.0.28, 10.1.62 and 9.0.124 the pool sends Connection.beginRequest() and endRequest() around each borrow (#677). The behaviour of endRequest() is vendor specific, and the Microsoft SQL Server driver (mssql-jdbc 13.2.1) closes every statement created during the request. A statement parked by StatementCache outlives the request, so every other borrow was handed a statement the driver had already closed (The statement is closed.). HSQLDB 2.7.4 fails the same way.

The hints are now sent only when the new useRequestBoundaries attribute is enabled (default false, the behaviour before 11.0.28), and never for a connection whose interceptor chain includes StatementCache.

Testing:

  • Tomcat with a JNDI jdbc-pool DataSource using the reporter's configuration, mssql-jdbc 13.2.1 and SQL Server 2022, 20 threads: 11.0.26 0 of 4000 failed, 11.0.29 3490 of 4000 failed. With this change 0 of 4000, also with useRequestBoundaries="true".
  • New tests in RequestBoundariesBase use a driver whose endRequest() closes the statements of the request. The StatementCache test fails on main with "The object is already closed". Removing the StatementCache guard makes the two tests that cover it fail.
  • All jdbc-pool tests pass (1098).

Since the pool sends Connection.beginRequest() and endRequest() around
each borrow, a statement cached by StatementCache could be closed
before it was used again. The behaviour of endRequest() is vendor
specific and the Microsoft SQL Server driver closes every statement
created during the request, so every other borrow was given a cached
statement the driver had already closed ("The statement is closed.").

Only send the hints when the new useRequestBoundaries attribute is
enabled, which restores the behaviour of previous releases by default,
and never for a connection whose interceptor chain includes
StatementCache, as a cached statement outlives the request it was
created in.
@rmaucher

Copy link
Copy Markdown
Contributor

Thanks for finding that me merging #677 cause the issue (it can also be a thread safety issue but ok), but it is probably not needed to autogenerate more stuff on top. This would always disable this feature basically, so the feature creep is pointless, and I should simply revert #677.

@rmaucher rmaucher closed this Nov 23, 2026
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.

2 participants