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

Command failed with error 251 (NoSuchTransaction) #4917

Open
KevinWqs opened this issue Mar 10, 2025 · 5 comments
Open

Command failed with error 251 (NoSuchTransaction) #4917

KevinWqs opened this issue Mar 10, 2025 · 5 comments
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Comments

@KevinWqs
Copy link

KevinWqs commented Mar 10, 2025

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)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 10, 2025
@KevinWqs
Copy link
Author

mongodb config:

package com.wms.config;

import com.wms.config.mongdo.MongoService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoTransactionManager;
import org.springframework.data.mongodb.config.EnableMongoAuditing;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.*;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.transaction.PlatformTransactionManager;

@EnableMongoAuditing
@configuration
public class MongoConfig {

@Bean
MappingMongoConverter mappingMongoConverter(
        MongoDatabaseFactory mongoDatabaseFactory,
        MongoMappingContext context, MongoCustomConversions conversions) {

    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory);
    MappingMongoConverter mappingMongoConverter =
            new MappingMongoConverter(dbRefResolver, context);
    mappingMongoConverter.setCustomConversions(conversions);
    mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
    return mappingMongoConverter;
}

@Bean(name = "mongoTransactionManager")
public MongoTransactionManager mongoTransactionManager(MongoDatabaseFactory factory) {
    return new MongoTransactionManager(factory);
}

@Bean
@Primary
public MongoTemplate mongoTemplate(MongoDatabaseFactory mongoDbFactory) {
    return new MongoTemplate(mongoDbFactory);
}

@Bean("mongoService")
public MongoService mongoService(MongoDatabaseFactory mongoDbFactory) {
    return new MongoService(mongoDbFactory);
}

}

@mp911de
Copy link
Member

mp911de commented Mar 10, 2025

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem.
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Mar 10, 2025
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Mar 17, 2025
@KevinWqs
Copy link
Author

OK, I need to figure out how to reproduce this problem, because it happens sporadically.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Mar 17, 2025
@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 17, 2025
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants