Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection closed for UPDATE BATCH_STEP_EXECUTION_CONTEXT [BATCH-2781] #823

Closed
spring-issuemaster opened this issue Dec 20, 2018 · 3 comments
Closed

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Dec 20, 2018

gvemula opened BATCH-2781 and commented

We are facing next error while updating tables. have anyone come across this?

We are using weblogic.

ERROR - JobRepository failure forcing exit with unknown status
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE STEP_EXECUTION_ID = ?]; SQL state [null]; error code [0]; Connection closed; nested exception is java.sql.SQLException: Connection closed
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:818)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:874)
at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.persistSerializedContext(JdbcExecutionContextDao.java:230)
at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.updateExecutionContext(JdbcExecutionContextDao.java:159)
at org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext(SimpleJobRepository.java:203)
at sun.reflect.GeneratedMethodAccessor1864.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)


Attachments:

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Dec 20, 2018

Mahmoud Ben Hassine commented

This is better asked on SO as someone else might already run through this error. Please ask the question on stackoverflow by providing the full stacktrace as well as your datasource/job configuration and the version of java/springbatch/weblogic etc.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 3, 2019

aakashgupta96 commented

Mahmoud Ben Hassine gvemula

Hi, we are also facing similar issue where connection is getting expired. We are using mysql server for maintaining job state. Let us say, we've kept wait_timeout on mysql server to be 2 minutes, i.e mysql will expire connection on it's side after 2 minute of inactivity of thread. 

Let us say, my write step of spring batch takes more than 2-3 minutes, in that case exception is thrown saying that acquired connection has already expired and can't do any operation on stale/dead thread. 

 

As per my understanding, this happens because:

  1. Framework acquires db connection from pool before getting into write method and it keeps that connection for as long as write (itemWriter) method executes.
  2. Let us say, this method took around 3-4 minutes for a chunk of data, then in the meantime the acquired connection by framework would already have been expired by mysql server.
  3. Whereas, framework doesn't know that connection has already expired and it tries to do a transaction to update job state.
  4. In that case, it fails saying that connection is broken/stale/closed. 

 

Can someone help us with handling this scenario? I'm attaching logs which depicts that above understanding is correct. Please search log file with '@112cfd7' which is connection object hash. 

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 4, 2019

Mahmoud Ben Hassine commented

If the connection expires before the job finishes, Spring Batch can do nothing about it. You need to configure your DB server to maintain connections alive for a sufficient amount of time. A similar thread on SO can be found here.

I'm closing this issue for now as it is better asked on SO (see my previous comment) and as it is not a Spring Batch issue IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.