Skip to content

Command failed with error 251 (NoSuchTransaction) #4917

Closed as not planned
Closed as not planned
@KevinWqs

Description

@KevinWqs

springboot 3.4 spring-boot-starter-data-mongodb [4.4.0]

  public R<PageVo<VehicleVo>> list(VehicleListDto dto)
  {
      Pageable pageable = PageRequest.of(dto.getPage(), dto.getLimit(), Sort.by(Sort.Direction.DESC, "id"));
      Criteria criteria = Criteria.where("del").is(0);
      Query query = new Query(criteria);
      long total = mongoTemplate.count(query, Vehicle.class);
      if (total == 0) {
          return R.ok(new PageVo(dto, total, null));
      }
      List<Vehicle> list = mongoTemplate.find(query.with(pageable), Vehicle.class);
      List<VehicleVo> listVo = list.stream().map(this::setExt).collect(Collectors.toList());
      return R.ok(new PageVo(dto, total, listVo));
  }


long total = mongoTemplate.count(query, Vehicle.class);
have error  like  below

It doesn't happen often, but sometimes. It happened a lot yesterday and it also happens in many other collections.

debug log:
org.springframework.data.mongodb.core.MongoTemplate - Executing count: {"del" : 0} in collection: t_vehicle"}

error log:

com.wms.util.ExceptionHandle - sys error
org.springframework.data.mongodb.TransientClientSessionException: Command failed with error 251 (NoSuchTransaction): 'Transaction with { txnNumber: 1 } has been aborted.' on server t-cluster-1-shard-00-01.f6mf6.mongodb.net:27017. The full response is {"errorLabels": ["TransientTransactionError"], "ok": 0.0, "errmsg": "Transaction with { txnNumber: 1 } has been aborted.", "code": 251, "codeName": "NoSuchTransaction", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1741521077, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "iovDdjX29gcTKy0fIfYb4iQBx/Y=", "subType": "00"}}, "keyId": 7471932593143808005}}, "operationTime": {"$timestamp": {"t": 1741521077, "i": 1}}}
	at org.springframework.data.mongodb.core.MongoExceptionTranslator.doTranslateException(MongoExceptionTranslator.java:144)
	at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:74)
	at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:3008)
	at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:605)
	at org.springframework.data.mongodb.core.MongoTemplate.doExactCount(MongoTemplate.java:1227)
	at org.springframework.data.mongodb.core.MongoTemplate.doCount(MongoTemplate.java:1196)
	at org.springframework.data.mongodb.core.MongoTemplate.count(MongoTemplate.java:1185)
	at org.springframework.data.mongodb.core.MongoTemplate.count(MongoTemplate.java:1161)
	at com.wms.servicemongo.outbound.VehicleService.list(VehicleService.java:245)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:723)
	at com.wms.servicemongo.outbound.VehicleService$$SpringCGLIB$$0.list(<generated>)
	at com.wms.controller.outbound.VehicleController.list(VehicleController.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:58)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions