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

System.StackOverflowException occurred in RDotNet.dll - simple repro with Keras and DotNet Core #90

Open
tomekziel opened this issue Mar 14, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@tomekziel
Copy link

commented Mar 14, 2019

Code below will consistently crash with "System.StackOverflowException occurred in RDotNet.dll"

Environment:
Windows 10 and Ubuntu 18.04 LTS
Runtime: DotNet Core 2.1
R version: 3.4.3 and 3.4.4 (vanilla and Microsoft edition)
RDotNet version: 1.7 from NuGet

On Windows (Visual Studio debug/release run) following code crashes consistently aroud loop 550 (+/- 50). On Ubuntu first use ulimit -s 768 and then dotnet run Program, it will fail between loop number 9k an 11k.

You can speed up crash by removing "using" directive and skipping manual dispose.

I will provide Visual Studio workspace, if needed.

        StartupParameter p = new StartupParameter();
        p.RHome = @"c:\Program Files\R\R-3.4.4\";
        //p.RHome = @"c:\Program Files\Microsoft\R Open\R-3.4.3\";
        REngine engine = REngine.GetInstance(parameter: p);

        engine.Evaluate("library(dplyr)");
        engine.Evaluate("library(keras)");
        engine.Evaluate("model <- keras_model_sequential() %>% layer_dense(units = 1000, input_shape = c(1000)) %>% compile(loss = 'mse',optimizer = 'adam')");

        int counter = 0;

        while (true)
        {

            Console.WriteLine(counter++);

            IntegerVector vec = engine.CreateIntegerVector(1000);
            vec.SetVector(new int[1000]);
            engine.SetSymbol("vec1000", vec);

            var execution = "predict(model, t(vec1000))";
            using (var output = engine.Evaluate(execution))
            {
                using (var a = output.AsList())
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        using (var b = a[i].AsNumeric())
                        {

                        }
                    }
                }
            };
        }
@jmp75

This comment has been minimized.

Copy link
Collaborator

commented Apr 15, 2019

Thank you @tomekziel for the reproducible report. I can indeed reproduce on R 3.4.4 on Windows 10, .net framework 4.0 (4.5.1). I didn't think the runtime could be DotNet Core 2.1 with R.NET 1.7.0 though, maybe I miss something because it is pretty clear you managed. Anyway, reproducible.

Unfortunately I have little insight into what is going on in the R (gcc) call stack that leads to a stack overflow. I really could do with mixed mode debugging across .NET and gcc compiled code here. Or if Microsoft had R compiled with VC++.

It does smell like a concurrency issue between .NET GC and R freeing resources.

@jmp75 jmp75 added the help wanted label Apr 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.