V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
stephCurry
V2EX  ›  Java

Springboot Mongodb 异步方法后插入出现 MongoInterruptedException

  •  
  •   stephCurry · 2020-05-14 00:03:16 +08:00 · 3115 次点击
    这是一个创建于 1433 天前的主题,其中的信息可能已经有所发展或是发生改变。

    异常信息:

    ERROR [task-2] org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler [handleUncaughtException#39] : Unexpected exception occurred invoking async method: public void org.cert.securityanalyzer.core.ScanEngine.run(java.util.List)
    org.springframework.data.mongodb.UncategorizedMongoDbException: Interrupted acquiring a permit to retrieve an item from the pool ; nested exception is com.mongodb.MongoInterruptedException: Interrupted acquiring a permit to retrieve an item from the pool 
        at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
        at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2783)
        at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:546)
        at org.springframework.data.mongodb.core.MongoTemplate.insertDocument(MongoTemplate.java:1433)
        at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1243)
    
    

    伪代码如下

    @Async
    public void scan(List<File> files) {
      files.foreach(f -> {
        try{
          scanSevice.scan(file);
          file.setSuccess(true);
        } catch (Exception e){
            file.setSuccess(false);
        }
    
        mongoTemplate.insert(file);
       })
    

    Google 了许多,有的说是因为其他线程 interrupted 导致,参见这篇 jira,我所依赖方法是多线程的,引用别人的 jar,属于我这边不可控的,的确,看到引用那边如果它的多线程出了异常,我这 mongo 就插不进去,如果没错误的话就能插进去,但是这是 mongo 的坑吧,直接测试FilsUtils.writeStringToFile是没问题的。


    依赖的方法异常片段:

    ERROR [Thread-74] heros.solver.CountingThreadPoolExecutor [afterExecute#64] : Worker thread execution failed: Opcode: IGET_BOOLEAN_QUICK @ 0x21
    java.lang.IllegalArgumentException: Opcode: IGET_BOOLEAN_QUICK @ 0x21
    	at soot.dexpler.instructions.InstructionFactory.fromOpcode(InstructionFactory.java:381)
    	at soot.dexpler.instructions.InstructionFactory.fromInstruction(InstructionFactory.java:48)
    	at soot.dexpler.DexBody.extractDexInstructions(DexBody.java:242)
    	at soot.dexpler.DexBody.<init>(DexBody.java:208)
    	at soot.dexpler.DexMethod$1.getBody(DexMethod.java:118)
    	at soot.SootMethod.retrieveActiveBody(SootMethod.java:402)
    	at soot.PackManager$3.run(PackManager.java:1293)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:748)
    

    已尝试的方法,但没用。。。

    • applciation.yml 里配置spring.data.mongodb.connectionTimeoutspring.data.mongodb.socketTimeout (时间为半小时,通常 10-20 多分钟扫完)
    • mongo 插入方法直接另起一个线程,不是怕关联线程被 Interrupted 吗,直接new Thread(() -> mongoTemplate.insert(file)).run()

    但是遗憾还不行。。。 大佬们是否遇到过此类情况?或者有什么建议方法?尽量不改现有框架把。。

    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3273 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:17 · PVG 21:17 · LAX 06:17 · JFK 09:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.