- I have searched the issues of this repository and believe that this is not a duplicate.
Ⅰ. Issue Description
TransactionPropagationInterceptor拦截器在请求异常时无清除线程里的xid,而HTTP请求是通过线程池共享线程的。当下一次请求拿到未清除xid的线程时就会报错。
Ⅱ. Describe what happened
If there is an exception, please attach the exception trace:
org.springframework.transaction.TransactionSystemException: JDBC commit failed; nested exception is java.sql.SQLException: io.seata.core.exception.RmTransactionException: Response[ TransactionException[Could not found global transaction xid = 192.168.22.11:8091 :252438693814513664, may be has finished.] ]\nat org.springframework.jdbc.datasource.DataSourceTransactionManager.translateException(DataSourceTransactionManager.java:435)\nat org.springframework.jdbc.support.JdbcTransactionManager.translateException(JdbcTransactionManager.java:188)\nat org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:336)\nat org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743)\nat org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)\nat org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:654)\nat org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:407)\nat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)\nat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
Ⅲ. Describe what you expected to happen
@OverRide
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) {
if (RootContext.inGlobalTransaction()) {
XidResource.cleanXid(request.getHeader(RootContext.KEY_XID));
}
}
改为:
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
if (RootContext.inGlobalTransaction()) {
XidResource.cleanXid(request.getHeader(RootContext.KEY_XID));
}
}
Ⅳ. How to reproduce it (as minimally and precisely as possible)
- 将HTTP请求线程池线程数设置为1。
- 请求中模拟异常请求。
- 查看RootContext中的xid值变化情况。
Ⅴ. Anything else we need to know?
Ⅵ. Environment:
- JDK version :
- Seata version: seata-all-1.4.2
- OS :
- Others:
1条答案
按热度按时间snz8szmq1#