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

AccessViolationException and app crash when working through proxy in multiple threads #1399

Closed
kpdenis opened this issue Oct 14, 2018 · 9 comments

Comments

@kpdenis
Copy link

kpdenis commented Oct 14, 2018

System

  • Version: 0.23.0-win64
  • Platform: Windows 7
  • Firefox: 62.0.3 (64 bit)
  • Selenium: 3.14.0

Testcase

  1. Create C# console app with code:
    class Program
    {
        static void Main(string[] args)
        {
            var proxies = new[]
            {
                "200.187.87.138:20183",
                "182.76.18.230:30073",
                "31.31.224.195:49160",
                "181.137.56.155:47756",
                "185.9.86.186:39345",
                "185.13.199.162:35702",
                "24.107.173.3:34370",
                "212.91.178.110:53281"
            };
            
            var threads = proxies.Select(x => new Thread(o => DoTest(x)))
                                 .ToList();

            foreach (var thread in threads)
                thread.Start();

            foreach (var thread in threads)
                thread.Join();
        }

        private static void DoTest(string proxy)
        {
            for (int i = 0; i < 10000; i++)
            {
                try
                {
                    using (var driver = CreateFireFox(proxy))
                    {
                        var r = Test(driver) ? "OK" : "FAIL";
                        Console.WriteLine($"{proxy} - [{r}]");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    // ignore Exception
                }
            }
        }

        private static bool Test(RemoteWebDriver driver)
        {
            try
            {
                // Do anything
                driver.Navigate().GoToUrl("https://www.seleniumhq.org/download/");
                return driver.FindElementsById("container").Any();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }

        private static RemoteWebDriver CreateFireFox(string proxy)
        {
            var execDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().GetName().CodeBase.Replace("file:///", ""));
            if (execDir == null) throw new Exception("Exec dir not found");

            var firefoxDriverPath = Path.Combine(execDir, "Firefox");
            var service = FirefoxDriverService.CreateDefaultService(firefoxDriverPath);
            service.FirefoxBinaryPath = Path.Combine(firefoxDriverPath, "firefox.exe");

            var options = new FirefoxOptions
            {
                Profile = new FirefoxProfile()
            };

            // Manual, see https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Mozilla_networking_preferences
            options.Profile.SetPreference("network.proxy.type", 1);

            var data = proxy.Split(':');
            var httpProxy = data[0];
            var port = int.Parse(data[1]);

            options.Profile.SetPreference("network.proxy.http", httpProxy);
            options.Profile.SetPreference("network.proxy.http_port", port);
            options.Profile.SetPreference("network.proxy.ssl", httpProxy);
            options.Profile.SetPreference("network.proxy.ssl_port", port);

            return new FirefoxDriver(service, options, TimeSpan.FromMinutes(1));
        }
    }
  1. copy FireFox v62.0.3 64 bit into bin/Debug/Firefox folder
  2. copy geckodriver.exe (0.23.0-win64) into bin/Debug/Firefox folder
  3. Run and wait

After working some time (about 5-10 minutes) this code raises exception "An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module." and app crash.

@andreastt
Copy link
Contributor

System.AccessViolationException would stem from C#, but it could be that some syscall in geckodriver causes it. Without better reproduction steps I’m not sure there’s anything we can do here. I doubt a trace-level log would help, and it’s also not certain it is the result of a geckodriver syscall in the first place.

😔

@kpdenis
Copy link
Author

kpdenis commented Oct 15, 2018

Did you check described test case?
How long did it work without crash?

On my computer this code produce crash every run, just wait...

Exception message: "An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt"

@andreastt
Copy link
Contributor

Sorry I didn’t try out the attached program because I don’t have access to a C# compiler or indeed a Windows machine.

There are a couple of hits when I google for “AccessViolationException” and “Rust” (which geckodriver is written in) so to be clear I’m not discounting that this is a problem in the Rust runtime on Windows.

@whimboo
Copy link
Collaborator

whimboo commented Oct 16, 2018

Could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

If that is a crash of Firefox I would be kinda interested in getting this investigated. Also please try the same with the latest Firefox 63 beta which can be downloaded from https://www.mozilla.org/en-US/firefox/channel/desktop/#beta.

@kpdenis
Copy link
Author

kpdenis commented Oct 19, 2018

Here are logs.

Notice that log not finished on error, so the problem probably not at the end of log file.
Other threads proceeds write log before I stop the process.

log.txt
log2.txt
log3.txt

@whimboo
Copy link
Collaborator

whimboo commented Oct 22, 2018

What are the differences between those logs? Also how many instances of geckodriver are you starting with your test job? As it looks like a couple of them. How does it work when you only make use of a single geckodriver process?

@kpdenis
Copy link
Author

kpdenis commented Oct 22, 2018

This three logs are independent tests, all of them contains different crash moment.

There are 8 threads, each creates a new geckodriver and after making test, dispose it.
This works in cycle, geckodriver creates and disposes many times.

Constructor new FirefoxDriver(...) starts new geckodriver process, so there is max 8 geckodriver processes working in same moment.

@whimboo
Copy link
Collaborator

whimboo commented Oct 24, 2018

Well, as such the flow of log entries is intersected and hard to follow. Is there a way for you to also see this with a single thread only? Or does it only happen with multiple threads? If that is the case maybe you can isolate the the log output for each thread, and only upload one which shows the problem.

@lock
Copy link

lock bot commented Aug 16, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants