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.Runtime.InteropServices.SEHException when trying to run multiple instances. #100

Open
alandixon opened this issue Mar 21, 2023 · 4 comments

Comments

@alandixon
Copy link

Specifically, I'm using the MultipleInstances demo project.

The variable parallelInstances is set to 4 by default.
For this value and any other value over 2, I intermittently get the SEHException, usually around the time everything starts to tear down.

After quite a lot of fiddling, I'm fairly sure the problem is to do with the virtual desktops;
If I force TorSharpSettings.ToolRunnerType to return ToolRunnerType.Simple, the problem goes away.
Of course, if I do that, I get a lot of popup privoxy windows, but it proves the point.

I am using Windows 10 64-bit which is why the ToolRunnerType defaults to VirtualDesktop.

I've tried lock in a few places to force single threading but not managed to isolate a vulnerable area of code.

The message is:

System.Runtime.InteropServices.SEHException
  HResult=0x80004005
  Message=External component has thrown an exception.

and the stack trace in Visual Studio 2022 is:

[Exception] System.Private.CoreLib.dll!Microsoft.Win32.SafeHandles.SafeFileHandle.ReleaseHandle()
[Exception] System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.InternalRelease(bool disposeOrFinalizeOperation)
[Exception] System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.Dispose(bool disposing)
[Exception] System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.~SafeHandle()
[Managed to Native Transition]	
System.Private.CoreLib.dll!Interop.Kernel32.CloseHandle(System.IntPtr handle)
System.Private.CoreLib.dll!Microsoft.Win32.SafeHandles.SafeFileHandle.ReleaseHandle()
System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.InternalRelease(bool disposeOrFinalizeOperation)
System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.Dispose(bool disposing)
System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.~SafeHandle()
@seanstardev
Copy link

I think this issue probably emerged immediately after 2.10.0 release. The System.Runtime.InteropServices.SEHException bug can be reproduced just by creating new Tor identities in quick succession, from my studies.

@seanstardev
Copy link

I also think I read about an arbitrary crash that can happen when using this library, and I definitely have experience of TorSharp crashing out pretty frequently. May be related to this bug - not sure.

All this said - it is a brilliant library and I really admire the work that has gone into it. Super impressive.

@joelverhagen
Copy link
Owner

Frankly, I wrote the Virtual Desktop code when I had less experience with PInvoke and Windows APIs. I think there are probably some bad assumptions in the implementation. I have only a little time these days to work on TorSharp due stuff in my personal life so if anyone has a chance to look at a fix or even provide a minimal repro, that might help. I'll leave this open since it appears it's not an isolated problem (4 upvotes).

@itHanVV
Copy link

itHanVV commented Nov 22, 2023

This happened to me in version 2.15.0 as well

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

No branches or pull requests

4 participants