I’m running a very complex project that generates thousands of CHR objects in addition to occasionally having quite deep Prolog calls. I’m discovering that if I run a certain process repeatedly, identical each time, it will succeed, delete all information, succeed, delete all information, stack overflow - catch exception, delete all information, succeed.
error(resource_error(stack),stack_overflow{choicepoints:529,depth:924,environments:45,globalused:523916,localused:755,stack:[frame(924,system: $collect_findall_bag(_38758826,),),frame(922,system:setup_call_catcher_cleanup((:)/2,(:)/2,_38758850,(:)/2),),frame(918,cp:class_get_item(56,qmc_plate_assembly,_38758892),),frame(917,cp:crgi([3],56,[1],_38758916,_38758918,_38758920),),frame(915,$bags:findall_loop(step/3,(:)/2,_38758954,),)],stack_limit:1048576,trailused:178046})ERROR: FAILED REQUEST (load_model(kb:project_extended))
Here’s the top-level loop, which is repeatedly receiving and executing the load_model request (and deleting the model). except/1 just converts exceptions to fail/0.
> lazy_service0 :-
> except(receive_term(Term))
> -> (except(dispatcher(Term, Response))
> -> (except(send_term(Response))
> -> ( Term == stop
> -> fail
> ; lazy_service0
> )
> ; writeln(failed_to_send(Response))
> , true
> )
> ; writeln('ERROR: FAILED REQUEST '(Term))
> , send_term(fail)
> , lazy_service0
> )
> ; true
> % , writeln('**********client disconnect**********')
> % , nl
> , true % send_term(fail)
> .
I don’t know what to do about this. It’s not the sort of thing I can make a small test case for because reducing the size will remove the overflow for sure.
I don’t understand why the stack would grow following repeated execution, or why a caught exception on one loop would clear it…
Maybe I can increase some stack sizes in the process?
Other suggestions?