fysh711426 / UndetectedChromeDriver

GNU General Public License v3.0
179 stars 66 forks source link

Multithreading issue after Update #36

Open JvB94 opened 1 year ago

JvB94 commented 1 year ago

Hi, thank you for your last update. I got a access problem now because it seems like you patcher try to patch the chromedriver multiple times and dont wait for the other process until its done. I guess that happens if i start to many instances at the same time.

Easy solution should be to wait until the file is accessable before execute using (FileStream fileStream = new FileStream(this._driverExecutablePath, FileMode.Open, FileAccess.ReadWrite)) in patchExe

Can you solve that?

  at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at SeleniumUndetectedChromeDriver.Patcher.patchExe()
   at SeleniumUndetectedChromeDriver.Patcher.Auto()
   at SeleniumUndetectedChromeDriver.UndetectedChromeDriver.Create(ChromeOptions options, String userDataDir, String driverExecutablePath, String browserExecutablePath, Int32 port, Int32 logLevel, Boolean headless, Boolean noSandbox, Boolean suppressWelcome, Boolean hideCommandPromptWindow, Nullable`1 commandTimeout, Dictionary`2 prefs, Action`1 configureService)
   at FCBZweitmarktBot.classes.BotThread.StartThread(CancellationToken token) in ...Thread.cs:line 109
fysh711426 commented 1 year ago

Is this any simpler?

var driverExecutablePath = 
    await new ChromeDriverInstaller().Auto();

var patcher = new Patcher(driverExecutablePath);
    patcher.Auto();

var createOptions = () =>
{
    var options = new ChromeOptions();
    return options;
};

var driver1 = UndetectedChromeDriver.Create(
    options: createOptions(),
    driverExecutablePath: driverExecutablePath);

var driver2 = UndetectedChromeDriver.Create(
    options: createOptions(),
    driverExecutablePath: driverExecutablePath);