Javet icon indicating copy to clipboard operation
Javet copied to clipboard

getEngine失败

Open weixiaodehuduo opened this issue 10 months ago • 1 comments

运行环境: linux x86_64主机 springboot+maven 集成依赖: <dependency> <groupId>com.caoccao.javet</groupId> <artifactId>javet</artifactId> <version>4.1.1</version> </dependency> <!-- Node.js Linux (x86_64) --> <dependency> <groupId>com.caoccao.javet</groupId> <artifactId>javet-node-linux-x86_64</artifactId> <version>${javet.version}</version> </dependency> <dependency> <groupId>com.caoccao.javet</groupId> <artifactId>javet-v8-linux-x86_64</artifactId> <version>${javet.version}</version> </dependency> 在程序运行过程中发现 getEngine失败 初始化engine失败,断点调试发现 存在 执行createEngine 失败 失败原因【Javet library is not loaded because 】,此时semaphore.tryAcquire()方法始终为false情况, 建议 异常情况下 主动 执行 semaphore.release()方法,问题代码如下 @Override public IJavetEngine<R> getEngine() throws JavetException { IJavetLogger logger = config.getJavetLogger(); logger.debug("JavetEnginePool.getEngine() begins."); JavetEngine<R> engine = null; long startTime = System.currentTimeMillis(); long lastTime = startTime; int retryCount = 0; while (!quitting) { if (semaphore.tryAcquire()) { try { Integer index = idleEngineIndexList.poll(); if (index == null) { index = releasedEngineIndexList.poll(); if (index != null) { engine = createEngine(); engine.setIndex(index); engines[index] = engine; break; } } else { engine = engines[index]; if (engine == null) { logger.error("Idle engine cannot be null."); engine = createEngine(); engine.setIndex(index); engines[index] = engine; } break; } semaphore.release(); } catch (Throwable t) { logger.logError(t, "Failed to create a new engine."); } } ++retryCount; if (retryCount >= config.getWaitForEngineMaxRetryCount()) { logger.logError("Failed to get an engine after {0} tries in {1}ms.", config.getWaitForEngineMaxRetryCount(), Long.toString(System.currentTimeMillis() - startTime)); throw new JavetException(JavetError.EngineNotAvailable); } try { TimeUnit.MILLISECONDS.sleep( config.getWaitForEngineSleepIntervalMillis()[ random.nextInt(config.getWaitForEngineSleepIntervalMillis().length)]); long currentTime = System.currentTimeMillis(); if (currentTime - lastTime >= config.getWaitForEngineLogIntervalMillis()) { logger.logWarn( "{0}ms passed while waiting for an idle engine.", Long.toString(currentTime - startTime)); lastTime = currentTime; } } catch (Throwable t) { logger.logError(t, "Failed to sleep a while to wait for an idle engine."); } } Objects.requireNonNull(engine).setActive(true); JavetEngineUsage usage = engine.getUsage(); usage.increaseUsedCount(); logger.debug("JavetEnginePool.getEngine() ends."); return engine; }

weixiaodehuduo avatar Feb 08 '25 04:02 weixiaodehuduo

Please review your config and design. The pool seems to have done this by design.

caoccao avatar Feb 08 '25 06:02 caoccao