neqsim icon indicating copy to clipboard operation
neqsim copied to clipboard

bug: Bad input causing `ProcessSystem.runAsThread()` to run into an infinite loop

Open soofstad opened this issue 1 year ago • 4 comments

Stacktrace from the bug causing ML/OilSep to loop indefinitely.

Just want to get this out there. @Sviatose might have some more information on the issue.

Hopefully it's possible to patch Neqsim so that is raises the Variable Molar volume is Nan-exception, instead of just logging it, and subsequently exits the loop.

07:39:42.131 [Thread-38067834] ERROR neqsim.thermo.phase.PhaseEos - PhasePrEos:molarVolume - Variable Molar volume is NaN
07:39:42.131 [Thread-38067834] ERROR neqsim.processSimulation.processSystem.ProcessSystem - neqsim.util.exception.IsNaNException: PhasePrEos:molarVolume - Variable Molar volume is NaN
java.lang.RuntimeException: neqsim.util.exception.IsNaNException: PhasePrEos:molarVolume - Variable Molar volume is NaN
	at neqsim.thermo.phase.PhaseEos.init(PhaseEos.java:112) ~[?:?]
	at neqsim.thermo.system.SystemThermo.initAnalytic(SystemThermo.java:3193) ~[?:?]
	at neqsim.thermo.system.SystemThermo.init(SystemThermo.java:3137) ~[?:?]
	at neqsim.thermodynamicOperations.flashOps.TPflash.run(TPflash.java:209) ~[?:?]
	at neqsim.thermodynamicOperations.ThermodynamicOperations.TPflash(ThermodynamicOperations.java:156) ~[?:?]
	at neqsim.processSimulation.processEquipment.util.Recycle.run(Recycle.java:326) ~[?:?]
	at neqsim.processSimulation.processSystem.ProcessSystem.run(ProcessSystem.java:446) [?:?]
	at neqsim.processSimulation.SimulationInterface.run(SimulationInterface.java:99) [?:?]
	at java.lang.Thread.run(Thread.java:840) [?:?]
Caused by: neqsim.util.exception.IsNaNException: PhasePrEos:molarVolume - Variable Molar volume is NaN
	at neqsim.thermo.phase.PhaseEos.molarVolume(PhaseEos.java:384) ~[?:?]
	at neqsim.thermo.phase.PhaseEos.init(PhaseEos.java:105) ~[?:?]
	... 8 more
INFO:     10.8.21.208:35292 - "POST /ML/oil-separation HTTP/1.1" 504 Gateway Timeout
INFO:2024-09-23 07:39:42,550 POST /ML/oil-separation - 55676ms - 504

soofstad avatar Oct 21 '24 14:10 soofstad

@soofstad Are you experiencing the same with the current version of neqsim? The line numbers does not match for me...

The function PhaseEos Init also appears to reraise the exception so perhaps it is already solved?

Image

asmfstatoil avatar Oct 24 '24 12:10 asmfstatoil

Should have mentioned, this was in v2.5.35. If you think the bug no longer can arise, we can close this issue 👍

soofstad avatar Oct 24 '24 12:10 soofstad

I have looked around, but I am currently not able to reproduce.

That said, there have not been made significant changes to the exception handling parts of this code since v2.5.35, so I will not close the issue yet.

asmfstatoil avatar Oct 25 '24 05:10 asmfstatoil

@asmfstatoil @Sviatose @AndreasHNyhus

This issue has been fixed in #1227 and fix is available in release 3.0.12+.

The problem was that a process thread is not stoped by calling join(time). Program continued to run in background.

In NeqSim versjon 3.0.12+ a process should be stopped using:

processThread.join(time_in_milliseconds); if (processThread.isAlive()) { processThread.interrupt(); processThread.join(); }

This will make sure the process will stop running, and should be used for all models running as Threads.

EvenSol avatar Jan 02 '25 17:01 EvenSol