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
Rdotnet application crash when GetFunction<setup_Rmainloop>()(); #139
Comments
I'm hitting the same problem using R 4.0.4 in the default install location on Windows |
R4.0.3 and R4.0.4 fail, R4.0.2 is OK for Windows Possible relevant discussion |
Have (finally, sorry it took so long...) started looking into this. Not sure if anyone else had made progress or has suggestions on places to look. I started by scanning the R changelog for 4.0.3, but nothing jumped out. Spent some time peeking at commits, but nothing jumped out either. Will dive more into individual commits, but realize that may just be a time sink. |
I'm not sure if I'm chasing a red herring here, but here's what I've found so far. First, just reproduced everything that was reported across various threads (not that I doubted any of you!)
Next step, let's see what we can get from the debugger. Visual Studio was showing me a crash coming from
I was hoping to get more information, so I loaded up Dr. Mingw and could see a more complete stack trace. Here's my first hint that I may be chasing something wrong - when I look at Then, I thought I'd spend some time looking at the changes from R 4.0.2 and 4.0.3. Nothing really jumped out at me around the call to But... one thing that DID catch my eye my eye was a change in Where this ended up then is a Trend Micro post that details changes in Windows 10 Anniversary Update with how it handles jumps, and explicitly mentions What this led me to is the question 'What if it's related to Windows 10 or Anniversary Update`? Again, this may be totally off base but I wanted to think through it. Just for fun, I loaded up a Windows 7 VM and discovered there is no crash with R 4.0.3 x64 in Windows 7. As I promised, this doesn't answer anything yet. It gives some clues and evidence that this may be related to the I'm going to keep going down this path, but wanted to share findings to date and see if anyone thinks I'm headed in the wrong direction. I'm still not comfortable with the fact that my stack trace from Dr. Mingw doesn't really match with the R source code, but it's consistently coming back to that call stack across other debuggers like |
Some progress in narrowing down the issue (will work on resolution next). It turns out I was mostly right. The stack trace I had posted was correct in the With a million thanks to r-windows/r-base, I was able to quickly and easily get a local copy of R built. I confirmed the crash occurred as we've seen. I then commented out the So it does seem this change in R 4.0.3 is what's causing our issue. It's still not 100% clear why it's only affecting x64, but these are the confirmations I needed to start figuring that out. In addition, having the ability to build R locally will allow me to enable debug symbols. |
Still no answers, but making my way through investigation. I adapted a simple C program from the main R code base that sets up and calls Code is here - https://github.com/lrasmus/rdotnet-r403-repro (it's dirty, just set up to work for me, but you can at least see what I'm doing). So while we appear to be calling the R.dll in the 'same' way from a C and a C# application, one works (C) and the other doesn't (C#). |
Able to find the root cause. This is apparently tied to Windows security feature Control Flow Guard. Using
Running
I am not going to recommend this en masse because it is decreasing security checks, but I can confirm that following these instructions and disabling CFG, my C# application no longer crashes. And just for fun, I enabled CFG on the C test app that was working... you guessed it - the crash starts appearing. Probably an easier way to do this is to disable CFG for any dotnet program. |
Proposed Solution - however, please know that this is removing the Control Flow Guard (CFG) security feature enabled by default in .NET apps, so it is up to you to perform a risk assessment and make an informed decision. This is following the previously posted steps to disable CFG for a dotnet program. From what I can tell, this must be done on the host application. So I don't believe this can be done on the official rdotnet assembly (I had tested this at least, and it didn't work for me). Here's what you'll need to do if you are building from Visual Studio:
A few things about step 4. In my setup, I was doing this for a test executable. The |
FYI - this has been reported to R-core: https://bugs.r-project.org/show_bug.cgi?id=18180 |
good to hear the cause of this issue wase founded, now the ball is in r-core or mingw or gcc team's court |
Irasmus, I had the same issues trying to convert to .Net 5.0, R 4.1.1 on Windows Server 2016. I had cloned the rdotnet and dynamic-interop gits and was seeing a problem at exactly the place. REngine worked fine until .Net 4.7.2 but not under .Net 5.0. Your work-around was able to solve the problem (at least until there is a permanent fix made). |
Progress - it sounds like the R team has found and proposed a fix! This is still in the development branch of R, but exciting that it seems we have a resolution on the horizon: https://bugs.r-project.org/show_bug.cgi?id=18180#c15 |
@lrasmus, thanks for all your work to get this debugged and fixed with the R team. Looks like we're all good now on the recently released 4.2.0: #r "nuget: R.NET"
open RDotNet
REngine.SetEnvironmentVariables("c:/program files/r/r-4.2.0/bin/x64", "c:/program files/r/r-4.2.0")
let engine = REngine.GetInstance()
engine
(* // output confirms on 4.2.0
val it: REngine = RDotNet.REngine {AutoPrint = false;
BaseNamespace = RDotNet.REnvironment;
Compatibility = ALTREP;
Disposed = false;
DllVersion = "4.2.0";
EmptyEnvironment = RDotNet.REnvironment;
EnableLock = true;
Filename = "R.dll";
GlobalEnvironment = RDotNet.REnvironment;
ID = "R.NET";
IsRunning = true;
NaString = RDotNet.SymbolicExpression;
NaStringPointer = 2240532559840n;
NilValue = RDotNet.SymbolicExpression;
UnboundValue = RDotNet.SymbolicExpression;}
*)
engine.Evaluate("letters[1:26]").AsCharacter()
// val it: CharacterVector = seq ["a"; "b"; "c"; "d"; ...] |
That's so good to hear @nhirschey, thanks!! |
wrtie a very simple c# application (build it and rdotnet both x64) , R 4.0.3 x86_64 installed at c:/soft/r ,but when install I choose no store information in registry
The text was updated successfully, but these errors were encountered: