gerardog/gsudo

Issue: gsudo --ti timeouts to `Error: Unable to connect to the elevated service`

joeyoropesa-dev opened this issue · 6 comments

Issue Description

In Admin command prompt:
Warning: System.NullReferenceException: Object reference not set to an instance of an object.
at gsudo.Rpc.NamedPipeClient.d__0.MoveNext() + 0x6e2
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
at gsudo.Helpers.ServiceHelper.d__1.MoveNext() + 0x116
Error: Unable to connect to the elevated service.

In non-admin command prompt:
Error: Unable to connect to the elevated service.

Steps to Reproduce

  1. Open Terminal/Command prompt as admin or non-admin
  2. Type gsudo/sudo --ti and even try after gsudo/sudo -k and even try to reboot the device, the results will be the same
  3. Result (Error)

Screenshots/Debug logs

Debug: Invoking Shell: Cmd
Debug: Command Line: --debug --ti
Debug: Command to run: C:\WINDOWS\System32\cmd.exe /k
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 8396
Debug: Caller SID: S-1-5-21-1141338512-3112617370-84707603-1001
Debug: Running: schtasks /Create /ru "NT SERVICE\TrustedInstaller" /TN "gsudo TI Cache for PID 8396" /TR ""C:\Program Files\gsudo\2.3.0\gsudo.exe" --debug -s --ti gsudoelevate 8396 S-1-5-21-1141338512-3112617370-84707603-1001 All 00:00:00" /sc ONCE /st 00:00 /f"
Debug: Process Start: schtasks /Create /ru "NT SERVICE\TrustedInstaller" /TN "gsudo TI Cache for PID 8396" /TR ""C:\Program Files\gsudo\2.3.0\gsudo.exe" --debug -s --ti gsudoelevate 8396 S-1-5-21-1141338512-3112617370-84707603-1001 All 00:00:00" /sc ONCE /st 00:00 /f"
WARNING: Task may not run because /ST is earlier than current time.
SUCCESS: The scheduled task "gsudo TI Cache for PID 8396" has successfully been created.
Debug: Process Start: schtasks /run /I /TN "gsudo TI Cache for PID 8396"
SUCCESS: Attempted to run the scheduled task "gsudo TI Cache for PID 8396".
Debug: Process Start: schtasks /delete /F /TN "gsudo TI Cache for PID 8396"
SUCCESS: The scheduled task "gsudo TI Cache for PID 8396" was successfully deleted.
Debug: Service process started.
Warning: System.NullReferenceException: Object reference not set to an instance of an object.
at gsudo.Rpc.NamedPipeClient.d__0.MoveNext() + 0x6e2
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
at gsudo.Helpers.ServiceHelper.d__1.MoveNext() + 0x116
Error: Unable to connect to the elevated service.

Context:

  • Windows version: Win11 23H2 - English
  • gsudo version: v2.3.0 (Branch.tags-v2.3.0.Sha.c7c3c9380a70bd004c4a3bebe9f54b86d836afbd)

Thanks for the report!

I've made a fix. I'm crossing fingers it fixes both scenarios. Would you please download this build and retest both (admin vs non-admin? That would be super helpfull.

Also, I was able to reproduce the issue only 20% of the times, so if you could check more than once! sorry if it is a lot to ask, but this project is mantained by me and those who volunteer, like you creating this accurate report :)

Please replace your gsudo.exe from this one: (Scroll down, go to Artifacts, download binaries)
https://github.com/gerardog/gsudo/actions/runs/5976346107

Dude I think you made me fix in 5 minutes the bug that has been haunting me for months!

Dude I think you made me fix in 5 minutes the bug that has been haunting me for months!

I'm glad that my issue helped you sir 🥰✨

I'm going right now to test this update on my PC ✨✨✨

This fix works but for example, when I start gsudo/sudo --ti for the first time in the terminal, it always shows that error - sometimes it shows 2x that error but after that, works. Also while TrustedInstaller is used usually by installers or something, the command still doesn't work

But anyway, the fix you provided here is much better than the older version. Anyway, I'm waiting for more responses in the future about getting more fixes about this error.

Thanks in advance and Thanks for the work you already done Sir! 🥰

Thanks for your feedback!
I've reworked the connection logic and changed the timeout handling.
Here is an updated build.