Jint: Memory Leak In Exception.

Created on 26 Jan 2021  路  5Comments  路  Source: sebastienros/jint

I use the Jint Version: 13.0.0-Beta-1767.
I found the Memory Leak as bellow:

image

Pls check it. Thank you.

bug

All 5 comments

Very nice screenshot. Can you attach code repro (as text, not image)?

This is my funtion:

public static string RunJavaScriptSchedule(GlobalScheduleModel _Schedule)
{
CancelTokenSourceEvent cancelToken = new CancelTokenSourceEvent();
try
{
SystemInterfaceBLL InterfaceFunctionObject = new SystemInterfaceBLL();
InterfaceFunctionObject.JavascriptScenesObj = _Schedule;

            // For prevent the endless loop => Can't Refesh to change Command Data. 
            // => Check the Scription is running or not. 
            // => If not => Adding CancelationTokenSource for manual Cancel.

            bool isOk = false;
            foreach(var cancelSource in TriggerCheckingService.CancelEventList.ToList())
            {
                if (cancelSource == null)
                {
                    TriggerCheckingService.CancelEventList.Remove(cancelSource);
                    continue;
                }

                if ((cancelSource.Id == _Schedule.Id) && (cancelSource.Type == EventType.ScheduleTrigger))
                {
                    if (cancelSource.NumberThread > 0) return "Error: More Than One Threads Are Running";     
                    cancelSource.NumberThread = 1;                  
                    isOk = true;
                    cancelToken = cancelSource;
                    break;
                }    
            }
            if(!isOk)
            {
                cancelToken = new CancelTokenSourceEvent(_Schedule.Id, EventType.ScheduleTrigger, 1);
                TriggerCheckingService.CancelEventList.Add(cancelToken);
            }    

            var engine = new Engine(options =>
            {
                // Use a cancellation token.
                options.CancellationToken(cancelToken.CancelSource.Token);
            });

            engine.SetValue("SystemLib", InterfaceFunctionObject);
            string command = _Schedule.JavaScriptAction;

            var result = "";
            try
            {
                result = engine.Execute(command).GetCompletionValue().ToString();
            }
            catch(Exception exp)
            {
                result = exp.ToString();
            }

            if (result.Trim() == "undefined") result = "";
            TriggerCheckingService.CancelEventList.Remove(cancelToken);

            // Update Data Only
            if ((result != "null") && (result.Trim() != "")) result = result + "\n"; else result = "";    
            string debug = _Schedule.Debug ?? "";

            GlobalScheduleDB.UpdateDebug(_Schedule, result + debug);
            GlobalScheduleDB.UpdateLastTime(_Schedule, Helper.UnixTime.GetCurrentMilliSecond());

            return (result + debug);
        }
        catch (Exception exp)
        {
            TriggerCheckingService.CancelEventList.Remove(cancelToken);
            var result = exp.ToString();
            // Update Data Only
            if ((result != "null") && (result.Trim() != "")) result = result + "\n"; else result = "";
            string debug = _Schedule.Debug ?? "";
            GlobalScheduleDB.UpdateDebug(_Schedule, result + debug);
            GlobalScheduleDB.UpdateLastTime(_Schedule, Helper.UnixTime.GetCurrentMilliSecond());

            return result;
        }
    }

Created an issue on Esprima side as it's better to fix it there first and then flow it to Jint.

Thanks @lahma, I see you fixed it, and could you tell me how long for next fix release?

It should show up on NuGet pretty soon, just uploaded. Thanks for reporting and details!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shestakov picture shestakov  路  10Comments

karoberts picture karoberts  路  3Comments

sebastienros picture sebastienros  路  34Comments

hnafar picture hnafar  路  3Comments

ciel picture ciel  路  13Comments