Or-tools: SegFault when calling ObjectiveValue or hasObjective

Created on 13 Nov 2020  路  3Comments  路  Source: google/or-tools

What version of OR-tools and what language are you using?
Version: v7.7.7810
Language: Java

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
Routing

What operating system (Linux, Windows, ...) and version?
MacOS

I am not sure what is going on. I am running the library on a dozen or so datasets and at some point it crashes due to a SegFault. It always happens when I do assignment.objectiveValue() as is evident by the JVM crash log:

---------------  S U M M A R Y ------------

Command Line: -javaagent:/Users/keremaslan/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/202.6397.94/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=54458:/Users/keremaslan/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/202.6397.94/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 com.connectedfreight.logistics.optimization.BenchmarkKt

Host: MacBookPro15,4 x86_64 1400 MHz, 8 cores, 16G, Darwin 19.6.0
Time: Thu Nov 12 19:45:33 2020 +08 elapsed time: 3204 seconds (0d 0h 53m 24s)

---------------  T H R E A D  ---------------

Current thread (0x00007f98c9809000):  JavaThread "main" [_thread_in_native, id=9731, stack(0x000070000aedd000,0x000070000afdd000)]

Stack: [0x000070000aedd000,0x000070000afdd000],  sp=0x000070000afdc780,  free space=1021k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libortools.dylib+0x44acc4]  operations_research::Assignment::ObjectiveValue() const+0x4
j  com.google.ortools.constraintsolver.mainJNI.Assignment_objectiveValue(JLcom/google/ortools/constraintsolver/Assignment;)J+0
j  com.google.ortools.constraintsolver.Assignment.objectiveValue()J+5
j  com.connectedfreight.logistics.optimization.ortools.adapters.OutputDomainModelAdapter.getVehicleRoutingPlan(Lcom/connectedfreight/logistics/optimization/ortools/Vrp;Lcom/google/ortools/constraintsolver/Assignment;Ljava/util/Map;Ljava/util/Set;)Lcom/connectedfreight/logistics/domain/solution/VehicleRoutingPlan;+62
j  com.connectedfreight.logistics.optimization.ortools.PdvrpSolver.solve(Lcom/connectedfreight/logistics/domain/problem/VehicleRoutingProblem;Lcom/connectedfreight/logistics/optimization/config/OeRequestConfiguration;)Lcom/connectedfreight/logistics/domain/solution/VehicleRoutingPlan;+180
j  com.connectedfreight.logistics.optimization.BenchmarkKt.main([Ljava/lang/String;)V+272

Note that this is after OR-Tools is done solving so assignment is never null. While this is odd I try to be more cautious and add a hasObjective() check before retrieving the objective. That however seems to cause the following crash:


---------------  S U M M A R Y ------------

Command Line: -javaagent:/Users/keremaslan/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/202.6397.94/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=59427:/Users/keremaslan/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/202.6397.94/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 com.connectedfreight.logistics.optimization.BenchmarkKt

Host: MacBookPro15,4 x86_64 1400 MHz, 8 cores, 16G, Darwin 19.6.0
Time: Fri Nov 13 13:20:48 2020 +08 elapsed time: 580 seconds (0d 0h 9m 40s)

---------------  T H R E A D  ---------------

Current thread (0x00007fe1bd80c000):  JavaThread "main" [_thread_in_native, id=6147, stack(0x0000700007ce7000,0x0000700007de7000)]

Stack: [0x0000700007ce7000,0x0000700007de7000],  sp=0x0000700007de6760,  free space=1021k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libjniortools.dylib+0x5b24]  _ZNK19operations_research21PropagationBaseObject6solverEv+0x4
C  [libjniortools.dylib+0x3af30]  _ZNK19operations_research10Assignment12HasObjectiveEv+0x10
C  [libjniortools.dylib+0x3af0c]  Java_com_google_ortools_constraintsolver_mainJNI_Assignment_1hasObjective+0xc
j  com.google.ortools.constraintsolver.mainJNI.Assignment_hasObjective(JLcom/google/ortools/constraintsolver/Assignment;)Z+0
j  com.google.ortools.constraintsolver.Assignment.hasObjective()Z+5

I have only taken the top part of the crash for brevity, but I can attach the full log if desired.

It is hard for me reproduce as it doesn't occur consequently with a single dataset. Rather, whilst running for several datasets sequentially, it crashes somewhere along the line. When I then try to reproduce it using that specific dataset, it runs just fine.

Also based on my observations this somehow only occurs when I run it locally and doesn't occur when I run it on a linux machine as part of our CI/CD, so far at least.

Is there a bug somewhere that cause this crash to happen locally and only when calling hasObjective() or objectiveValue()?

Bug Java Mac Routing Solver

All 3 comments

I think our current wrapper implementation is not robust to "multiple solves" in the same process when using Java...
I suspect some global being not properly reclaimed by the garbage collector.

do you know which JDK is installed on your machine ? also v7.7 seems quite old did you try the last v8.0 release ?
note: we also provide maven package (not uploaded on maven central yet but you can find them in prebuilt archive)
e.g. https://github.com/google/or-tools/releases/download/v8.0/or-tools_MacOsX-10.15.7_v8.0.8283.tar.gz

can be related to #2091

The JDK I run on is 14.

Interesting. I run it sequentially in a loop where in each step of the loop a new problem gets loaded, the solver is run and the result is collected. Would that still cause issues with the GC?

I'll try to upgrade to V8.0 as well. (I am using Maven, so I hope it gets uplaoded to Maven Central soon!)

Was this page helpful?
0 / 5 - 0 ratings