You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am still investigating what's happening here, but it appears that the max_memory limit is only enforced when running Javascript code through the exec method - see the code setting the data point on the isolate and the AddGCEpilogueCallback here, in the nogvl_context_eval method. No comparable code seems to be present in the nogvl_context_call method.
The code that I am currently working with loads a few hundred lines of JS via the eval method which defines various Javascript functions, and then calls the defined methods with Ruby objects using the call method. I was hoping to use the max_memory limit in this code to prevent excessive memory consumption, but it does not seem to be effective. I added a log line to the C callback function gc_callback, and the memory limits I set appear to get stomped by the time I run any of the defined functions - when it runs, it thinks that the softlimit is some random huge value.
At this stage, what I am asking is whether there is an intentional reason for this. If this is not an intended behavior, I am open to creating a test exercising this, and writing a fix.
The text was updated successfully, but these errors were encountered:
I've been looking into this some more. Based on what I've seen, it seems that something is overwriting the value for the MEM_SOFTLIMIT_VALUE in the isolate under some conditions. When I tried to write a Ruby test for it in mini_racer, it was overwritten to 0, and would exit on the first GC run. When I was running the original code in the application I'm working, it would get overwritten to a very high value, and would never trigger. I see 2 possible ways to address this issue:
Figure out and fix whatever is overwriting the MEM_SOFTLIMIT_VALUE. I am not an expert in C++, and probably don't have bandwidth to figure that out.
Add a bit of code in nogvl_context_call to set the memory limit if present, just like is already present in nogvl_context_eval. I have implemented this locally and tested it, and it seems to work as expected, both in the test I wrote on mini_racer, and in our application. I'll open a PR with this change.
One other note - it doesn't seem to be possible to write a Ruby test exercising this issue. The memory limiter still runs with or without the fix, it just runs with an incorrect value for MEM_SOFTLIMIT_VALUE, and thus terminates at the wrong time.
I am still investigating what's happening here, but it appears that the
max_memory
limit is only enforced when running Javascript code through theexec
method - see the code setting the data point on the isolate and theAddGCEpilogueCallback
here, in thenogvl_context_eval
method. No comparable code seems to be present in thenogvl_context_call
method.The code that I am currently working with loads a few hundred lines of JS via the
eval
method which defines various Javascript functions, and then calls the defined methods with Ruby objects using thecall
method. I was hoping to use themax_memory
limit in this code to prevent excessive memory consumption, but it does not seem to be effective. I added a log line to the C callback functiongc_callback
, and the memory limits I set appear to get stomped by the time I run any of the defined functions - when it runs, it thinks that the softlimit is some random huge value.At this stage, what I am asking is whether there is an intentional reason for this. If this is not an intended behavior, I am open to creating a test exercising this, and writing a fix.
The text was updated successfully, but these errors were encountered: