Springboot Mongodb 异步方法后插入出现 MongoInterruptedException - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
stephCurry
V2EX    Java

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

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

    异常信息:

    ERROR [task-2] org.springframework.aop.interceptor.SimpleAsyncUnaughtExceptionHandler [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     Solana     1251 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 17:19 PVG 01:19 LAX 09:19 JFK 12:19
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86