[JBoss JIRA] (JBJCA-1355) set-tx-query-timeout does not work when the remaining transaction timeout is shorter than one second
by Masafumi Miura (JIRA)
[ https://issues.jboss.org/browse/JBJCA-1355?page=com.atlassian.jira.plugin... ]
Masafumi Miura updated JBJCA-1355:
----------------------------------
Git Pull Request: https://github.com/ironjacamar/ironjacamar/pull/637, https://github.com/ironjacamar/ironjacamar/pull/638
> set-tx-query-timeout does not work when the remaining transaction timeout is shorter than one second
> ----------------------------------------------------------------------------------------------------
>
> Key: JBJCA-1355
> URL: https://issues.jboss.org/browse/JBJCA-1355
> Project: IronJacamar
> Issue Type: Bug
> Components: JDBC
> Reporter: Masafumi Miura
>
> {{set-tx-query-timeout}} setting does not work when the remaining transaction timeout is shorter than one second (between 0-999 millis) due to incorrect round-up in IronJacamar {{WrapperDataSource#getTimeLeftBeforeTransactionTimeout()}}.
> ---
> {{WrappedConnection#checkConfiguredQueryTimeout()}} checks the returned value from {{WrapperDataSource#getTimeLeftBeforeTransactionTimeout()}} and set the value to query timeout if it's larger than 0. If it's not larger than 0, the configured query timeout ({{query-timeout}} in datasource setting) is used. This behavior itself is ok.
> However, {{WrapperDataSource#getTimeLeftBeforeTransactionTimeout()}} incorrectly rounds up the returned value from transaction manager's {{TransactionTimeoutConfiguration#getTimeLeftBeforeTransactionTimeout()}}. And it results in returning 0 when the remaining transaction timeout is between 0-999 millis. This causes the issue.
> Here's the related code from 1.3.7.Final (It's same in the latest 1.3 branch and 1.4 branch):
> - https://github.com/ironjacamar/ironjacamar/blob/ironjacamar-1.3.7.Final/a...
> {code}
> 2022 /**
> 2023 * Check configured query timeout
> 2024 * @param ws The statement
> 2025 * @param explicitTimeout An explicit timeout value set
> 2026 * @exception SQLException Thrown if an error occurs
> 2027 */
> 2028 void checkConfiguredQueryTimeout(WrappedStatement ws, int explicitTimeout) throws SQLException
> 2029 {
> 2030 if (mc == null || dataSource == null)
> 2031 return;
> 2032
> 2033 int timeout = 0;
> 2034
> 2035 // Use the transaction timeout
> 2036 if (mc.isTransactionQueryTimeout())
> 2037 {
> 2038 timeout = dataSource.getTimeLeftBeforeTransactionTimeout();
> 2039 if (timeout > 0 && explicitTimeout > 0 && timeout > explicitTimeout)
> 2040 timeout = explicitTimeout;
> 2041 }
> 2042
> 2043 // Look for a configured value
> 2044 if (timeout <= 0 && explicitTimeout <= 0)
> 2045 timeout = mc.getQueryTimeout();
> 2046
> 2047 if (timeout > 0)
> 2048 ws.setQueryTimeout(timeout);
> 2049 }
> {code}
> - https://github.com/ironjacamar/ironjacamar/blob/ironjacamar-1.3.7.Final/a...
> {code}
> 190 /**
> 191 * Get the time left before a transaction timeout
> 192 * @return The amount in seconds; <code>-1</code> if no timeout
> 193 * @exception SQLException Thrown if an error occurs
> 194 */
> 195 protected int getTimeLeftBeforeTransactionTimeout() throws SQLException
> 196 {
> 197 try
> 198 {
> 199 if (cm instanceof TransactionTimeoutConfiguration)
> 200 {
> 201 long timeout = ((TransactionTimeoutConfiguration) cm).getTimeLeftBeforeTransactionTimeout(true);
> 202 // No timeout
> 203 if (timeout == -1)
> 204 return -1;
> 205 // Round up to the nearest second
> 206 long result = timeout / 1000;
> 207 if ((result % 1000) != 0)
> 208 ++result;
> 209 return (int) result;
> 210 }
> 211 else
> 212 return -1;
> 213 }
> 214 catch (RollbackException e)
> 215 {
> 216 throw new SQLException(e);
> 217 }
> 218 }
> {code}
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
6 years, 6 months
[JBoss JIRA] (JBJCA-1355) set-tx-query-timeout does not work when the remaining transaction timeout is shorter than one second
by Masafumi Miura (JIRA)
Masafumi Miura created JBJCA-1355:
-------------------------------------
Summary: set-tx-query-timeout does not work when the remaining transaction timeout is shorter than one second
Key: JBJCA-1355
URL: https://issues.jboss.org/browse/JBJCA-1355
Project: IronJacamar
Issue Type: Bug
Components: JDBC
Reporter: Masafumi Miura
{{set-tx-query-timeout}} setting does not work when the remaining transaction timeout is shorter than one second (between 0-999 millis) due to incorrect round-up in IronJacamar {{WrapperDataSource#getTimeLeftBeforeTransactionTimeout()}}.
---
{{WrappedConnection#checkConfiguredQueryTimeout()}} checks the returned value from {{WrapperDataSource#getTimeLeftBeforeTransactionTimeout()}} and set the value to query timeout if it's larger than 0. If it's not larger than 0, the configured query timeout ({{query-timeout}} in datasource setting) is used. This behavior itself is ok.
However, {{WrapperDataSource#getTimeLeftBeforeTransactionTimeout()}} incorrectly rounds up the returned value from transaction manager's {{TransactionTimeoutConfiguration#getTimeLeftBeforeTransactionTimeout()}}. And it results in returning 0 when the remaining transaction timeout is between 0-999 millis. This causes the issue.
Here's the related code from 1.3.7.Final (It's same in the latest 1.3 branch and 1.4 branch):
- https://github.com/ironjacamar/ironjacamar/blob/ironjacamar-1.3.7.Final/a...
{code}
2022 /**
2023 * Check configured query timeout
2024 * @param ws The statement
2025 * @param explicitTimeout An explicit timeout value set
2026 * @exception SQLException Thrown if an error occurs
2027 */
2028 void checkConfiguredQueryTimeout(WrappedStatement ws, int explicitTimeout) throws SQLException
2029 {
2030 if (mc == null || dataSource == null)
2031 return;
2032
2033 int timeout = 0;
2034
2035 // Use the transaction timeout
2036 if (mc.isTransactionQueryTimeout())
2037 {
2038 timeout = dataSource.getTimeLeftBeforeTransactionTimeout();
2039 if (timeout > 0 && explicitTimeout > 0 && timeout > explicitTimeout)
2040 timeout = explicitTimeout;
2041 }
2042
2043 // Look for a configured value
2044 if (timeout <= 0 && explicitTimeout <= 0)
2045 timeout = mc.getQueryTimeout();
2046
2047 if (timeout > 0)
2048 ws.setQueryTimeout(timeout);
2049 }
{code}
- https://github.com/ironjacamar/ironjacamar/blob/ironjacamar-1.3.7.Final/a...
{code}
190 /**
191 * Get the time left before a transaction timeout
192 * @return The amount in seconds; <code>-1</code> if no timeout
193 * @exception SQLException Thrown if an error occurs
194 */
195 protected int getTimeLeftBeforeTransactionTimeout() throws SQLException
196 {
197 try
198 {
199 if (cm instanceof TransactionTimeoutConfiguration)
200 {
201 long timeout = ((TransactionTimeoutConfiguration) cm).getTimeLeftBeforeTransactionTimeout(true);
202 // No timeout
203 if (timeout == -1)
204 return -1;
205 // Round up to the nearest second
206 long result = timeout / 1000;
207 if ((result % 1000) != 0)
208 ++result;
209 return (int) result;
210 }
211 else
212 return -1;
213 }
214 catch (RollbackException e)
215 {
216 throw new SQLException(e);
217 }
218 }
{code}
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
6 years, 6 months