Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow exception when using '()' chars with .net framwork 4.8 #136

Closed
Beckdotan opened this issue Jul 9, 2024 · 13 comments · Fixed by #184
Closed

Stack overflow exception when using '()' chars with .net framwork 4.8 #136

Beckdotan opened this issue Jul 9, 2024 · 13 comments · Fixed by #184

Comments

@Beckdotan
Copy link

Beckdotan commented Jul 9, 2024

Hi All,

In my project that is using Ncalc and parlot in a complicated way, I got some weird error (stack overflow) since Ncalc 4.0 where they started using parlot as their parser.

Since when I delete the .complie call from their repository it work, they suggested its problem in here.

So, to cancel all other attributes, I just created a new Angular and .NET framework 4.8 project, just like my main project is, and created API to run these commands only!

string question = "(1+2)*3";
var expression = new Expression(question);
return (int)expression.Evaluate();

And I get the stack overflow, but when running it with: question = "1+2*3"; is doing just fine!

It seems like the combination of my framework + the '()' cars are causing problems, that are being solved when I delete the .compile command.

some addition information that might be useful:
Since framework 4.8 is only working with c#6, I have polysharp set to 'latest' c# version.
I'm using NCalc version 4.3.3

Maybe its the combination between old framework with the latest version of c# with polysharp?
Because just before the .compile there is this function:

#if NET6_0_OR_GREATER
        if (System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported)
            Parser = expressionParser.Compile();
        else
            Parser = expressionParser;
#else
        Parser = expressionParser;.Compile(); // -> this is the compile that when I delete to make it work
#endif

When my code enters the else part, but since I am using Poly sharp my c# is in the newest version, so it might need to get into the if section?

@sebastienros
Is there any more information I can add to help?

@Beckdotan
Copy link
Author

Update -> even if I delete Poly sharp from the project, and not its just a .NET Framework 4.8 project, it still doesn't work. so it have nothing to do with Poly sharp.

@sebastienros
Copy link
Owner

I just created a new Angular and .NET framework 4.8 project

So just these 3 lines, a reference to NCalc, and it crashes? Or is it after adding a lot more code that you wrote for your app?

Either way you should create a GH repository with the project as it is failing. Then at least there is a way for me to easily make it fail locally so I can debug it.

Even better, once it's failing, remove some code (like you did with poly), if it still fails remove some more, until it doesn't fail anymore. At that point we know what is triggering the problem.

If you had to add more code than just these 3 lines then you need to share the stack trace showing the cyclic code. This will help show where the stackoverflow is originating from.

@Bykiev
Copy link

Bykiev commented Jul 9, 2024

I don't know why, but this simple expression evaluates in .NET Framework almost 10x time slower than with .NET 6. My app is not crashing, but it can be due environment.
@Beckdotan, do you have an antivirus installed?

@Beckdotan
Copy link
Author

Beckdotan commented Jul 9, 2024

@Bykiev I do have Mcfee but I turned it off and I still got stack overflow.

@Beckdotan
Copy link
Author

I just created a new Angular and .NET framework 4.8 project

So just these 3 lines, a reference to NCalc, and it crashes? Or is it after adding a lot more code that you wrote for your app?

Either way you should create a GH repository with the project as it is failing. Then at least there is a way for me to easily make it fail locally so I can debug it.

Even better, once it's failing, remove some code (like you did with poly), if it still fails remove some more, until it doesn't fail anymore. At that point we know what is triggering the problem.

If you had to add more code than just these 3 lines then you need to share the stack trace showing the cyclic code. This will help show where the stackoverflow is originating from.

@sebastienros These 3 lines are the only code that I have a part of the surrounding code of the AngularJS and .NET framework application.
I will open a repo with this project and will send a link to it here.

@sebastienros
Copy link
Owner

@Beckdotan I'll be waiting for your simple app on GH. I tried myself with a console app (since it should be the same) on 4.7.2 and it worked.

@Bykiev The first evaluation seems outrageously slow, which is probably because of the time it takes to compile the parser on the first use. Then it's fast.

@Beckdotan
Copy link
Author

@sebastienros @Bykiev
https://github.com/Beckdotan/NcalcTestApp.git

Here is a very minimalistic app that is failing when entering the expression "(1+2)*3"

@sebastienros
Copy link
Owner

I installed .net framework 4.8 (only had 4.7.2 before that), cloned and opened your solution, ran it, can't repro any issue. Also I don't see why you would not create a console app instead since it would be simpler to implement than a web one.

Screen.Recording.2024-07-10.000904.mp4

@Beckdotan
Copy link
Author

Beckdotan commented Aug 4, 2024

Hi, @sebastienros
Thanks for the checks.
After your comment I did few more tests.

I ran my code on different computer, and it failed.
I created a CLI app as suggested and it worked!

So I decided to download Ncalc and Parlot and debug, and run the Angular&.net app and now I have some more information.

Here are 2 screenshots that shows where exactly in parlot I get the error and the call stack and the parameters avaliable at that point.
It fails on row 22.

Screenshot 2024-08-04 152730

image

Screenshot 2024-08-04 153109

Please let me know if I can help even more.

@Beckdotan
Copy link
Author

Hi, @sebastienros Thanks for the checks. After your comment I did few more tests.

I ran my code on different computer, and it failed. I created a CLI app as suggested and it worked!

So I decided to download Ncalc and Parlot and debug, and run the Angular&.net app and now I have some more information.

Here are 2 screenshots that shows where exactly in parlot I get the error and the call stack and the parameters avaliable at that point. It fails on row 22.

Screenshot 2024-08-04 152730

image ![Screenshot 2024-08-04 153109](https://private-user-images.githubusercontent.com/78174171/354902367-0b9ca396-dd69-4560-964f-51b4f4cb6294.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyODg4OTEsIm5iZiI6MTcyNTI4ODU5MSwicGF0aCI6Ii83ODE3NDE3MS8zNTQ5MDIzNjctMGI5Y2EzOTYtZGQ2OS00NTYwLTk2NGYtNTFiNGY0Y2I2Mjk0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAyVDE0NDk1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE1OTk5Y2UwYmNiYjg1MmMzMGYzMjM4ZDI0YTA4NTJhYWUxMTU1YzVjNDFjMjE0NGQ5NDY1MWY5NTQwOWYzOWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.MXHPRS4EemTQJNX3day03-inKXEqPClYcDAv9hppmh4)

Please let me know if I can help even more.

@sebastienros Is there any more information do you want me to supply?

Thanks again!

@sebastienros
Copy link
Owner

My last comment was that the application you provided to repro the issue doesn't fail on my computer.

I am still waiting for a repro case to debug it.

In parallel, on this screen shot you shared

image

Can you show (the text is fine) what is behind "Show Call Stack", it would be interesting what is the call stack if this is so "big" that it overflows. The goal being to identify an infinite recursive call. Showing what triggers it (Line 22) is not sufficient.

@sebastienros
Copy link
Owner

Optionally if you have it failing in VS with all the source code, please Skype me (sebastienros) and I can spend some time guiding you on how to get more information and identifying the issue.

@Beckdotan
Copy link
Author

Optionally if you have it failing in VS with all the source code, please Skype me (sebastienros) and I can spend some time guiding you on how to get more information and identifying the issue.

thanks! i sent you a request on skype.

Here is the call stack
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants