apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.35k stars 8.78k forks source link

Seata XA Throws an ShouldNeverHappenException after insert into #6130

Closed liuyaorong closed 2 months ago

liuyaorong commented 11 months ago

About Version seata-server version:1.7.1 seata-spring-boot-starter:1.5.2 mysql version:8.0.35

Please refer to the following content for abnormal information:

2023-12-08 16:31:35.609 DEBUG 23248 --- [http-nio-9022-exec-4] c.a.c.seata.web.SeataHandlerInterceptor : xid in RootContext null xid in RpcContext 192.168.119.168:8091:3062913006613929985 2023-12-08 16:31:35.610 DEBUG 23248 --- [http-nio-9022-exec-4] c.a.c.seata.web.SeataHandlerInterceptor : bind 192.168.119.168:8091:3062913006613929985 to RootContext 2023-12-08 16:31:35.689 INFO 23248 --- [http-nio-9022-exec-4] c.y.o.m.c.f.PointMallFeignController : pointMallOrderBo: PointMallOrderBo(pointMallId=0, productType=1, orderId=1325, orderNo=BD231208100006200, spuId=263, spuCode=68730, spuName=英雄玩具 特利迦奥特曼-胜利超越之钥 永恒闪耀特利迦之钥, skuId=427, skuCode=6974995177303, skuName=英雄玩具 特利迦奥特曼-胜利超越之钥 永恒闪耀特利迦之钥, couponId=null, couponName=null, couponMemberId=null, points=100, number=1, orderTime=Fri Dec 08 16:31:35 CST 2023, memberId=15, memberName=楽子) 2023-12-08 16:31:36.370 DEBUG 23248 --- [http-nio-9022-exec-4] c.y.o.m.m.P.insertSelective : ==> Preparing: insert into marketing_point_exchange ( point_mall_id, product_type, order_id, order_no, spu_id, spu_code, spu_name, sku_id, sku_code, sku_name, points, number, order_time, member_id, member_name, create_time, update_time ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 2023-12-08 16:31:36.376 DEBUG 23248 --- [http-nio-9022-exec-4] c.y.o.m.m.P.insertSelective : ==> Parameters: 0(Long), 1(Byte), 1325(Long), BD231208100006200(String), 263(Long), 68730(String), 英雄玩具 特利迦奥特曼-胜利超越之钥 永恒闪耀特利迦之钥(String), 427(Long), 6974995177303(String), 英雄玩具 特利迦奥特曼-胜利超越之钥 永恒闪耀特利迦之钥(String), 100(Integer), 1(Integer), 2023-12-08 16:31:35.0(Timestamp), 15(Long), 楽子(String), 2023-12-08 16:31:35.689(Timestamp), 2023-12-08 16:31:35.689(Timestamp) 2023-12-08 16:31:36.396 DEBUG 23248 --- [http-nio-9022-exec-4] c.y.o.m.m.P.insertSelective : <== Updates: 1 2023-12-08 16:31:36.396 DEBUG 23248 --- [http-nio-9022-exec-4] c.y.o.m.m.P.insertSelective!selectKey : ==> Preparing: SELECT LAST_INSERT_ID() 2023-12-08 16:31:36.396 DEBUG 23248 --- [http-nio-9022-exec-4] c.y.o.m.m.P.insertSelective!selectKey : ==> Parameters: 2023-12-08 16:31:36.403 INFO 23248 --- [http-nio-9022-exec-4] y.o.m.w.h.MarketingFeignExceptionHandler : Exception:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: io.seata.common.exception.ShouldNeverHappenException: something wrong with keeper, keeping[null] but[io.seata.rm.datasource.xa.ConnectionProxyXA@7f5fba6d] is also kept with the same key[192.168.119.168:8091:3062913006613929985-3062913006613929990] at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) at com.sun.proxy.$Proxy129.insert(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:272) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62) at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) at com.sun.proxy.$Proxy198.insertSelective(Unknown Source) at com.yoren.omo.marketing.service.impl.PointExchangeServiceImpl.addPointExchange(PointExchangeServiceImpl.java:45) at com.yoren.omo.marketing.controller.feign.PointMallFeignController.handlePointMallOrder(PointMallFeignController.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1070) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at com.yoren.omo.common.web.filter.EncryptionFilter.doFilter(EncryptionFilter.java:33) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at com.yoren.omo.common.web.filter.DecryptFilter.doFilter(DecryptFilter.java:37) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at com.yoren.omo.common.operator.filter.OperatorIdFilter.doFilterInternal(OperatorIdFilter.java:41) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:750) Caused by: org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: io.seata.common.exception.ShouldNeverHappenException: something wrong with keeper, keeping[null] but[io.seata.rm.datasource.xa.ConnectionProxyXA@7f5fba6d] is also kept with the same key[192.168.119.168:8091:3062913006613929985-3062913006613929990] at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:90) at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processAfter(SelectKeyGenerator.java:54) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:51) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy244.update(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ... 68 common frames omitted Caused by: io.seata.common.exception.ShouldNeverHappenException: something wrong with keeper, keeping[null] but[io.seata.rm.datasource.xa.ConnectionProxyXA@7f5fba6d] is also kept with the same key[192.168.119.168:8091:3062913006613929985-3062913006613929990] at io.seata.rm.BaseDataSourceResource.hold(BaseDataSourceResource.java:176) at io.seata.rm.datasource.xa.ConnectionProxyXA.keepIfNecessary(ConnectionProxyXA.java:98) at io.seata.rm.datasource.xa.ConnectionProxyXA.setAutoCommit(ConnectionProxyXA.java:175) at io.seata.rm.datasource.xa.ExecuteTemplateXA.execute(ExecuteTemplateXA.java:41) at io.seata.rm.datasource.xa.PreparedStatementProxyXA.execute(PreparedStatementProxyXA.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy246.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:151) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy244.query(Unknown Source) at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:67) ... 87 common frames omitted

funky-eyes commented 10 months ago

请给我一个能复现此问题的示例 Please give me an example to reproduce this problem

funky-eyes commented 10 months ago

这应该是一个bug,在这个异常发生之前应该也发生过另外一种异常,比如commit,rollback,setautocommit等方法的调用时触发了异常,导致connectionproxyxa的状态没有被重置正确,然后这个connectionproxyxa被复用了导致了这个问题出现。 This should be a bug. Before this exception occurs, another exception should have occurred. For example, the call of commit, rollback, setautocommit, etc. triggers an exception, causing the state of connectionproxyxa to not be reset correctly. Then the connectionproxyxa is reused, causing this problem.

funky-eyes commented 10 months ago

我上面的结论并不对,通过这种方式无法复现该问题,你这边能提供相关示例或demo吗? My conclusion above is not correct. The problem cannot be reproduced in this way. Can you provide relevant examples or demos?