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

Do/Undo Commands fail to work after executing a certain amount of times #1456

Closed
3 tasks done
Nonary opened this issue Jul 19, 2023 · 8 comments · Fixed by #1334
Closed
3 tasks done

Do/Undo Commands fail to work after executing a certain amount of times #1456

Nonary opened this issue Jul 19, 2023 · 8 comments · Fixed by #1334
Labels
fixed This issue has been fixed and will be available in the next release. os:Windows OS is Windows

Comments

@Nonary
Copy link
Collaborator

Nonary commented Jul 19, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Is your issue described in the documentation?

  • I have read the documentation

Is your issue present in the nightly release?

  • This issue is present in the nightly release

Describe the Bug

Sunshine will fail to execute do/undo commands after executing them a certain number of times, appears to be intermitent.

To replicate the bug:

Add an app with the following do/undo commands:

        {
            "name": "Debug",
            "output": "",
            "cmd": "",
            "exclude-global-prep-cmd": "true",
            "elevated": "false",
            "prep-cmd": [
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                },
                {
                    "do": "",
                    "undo": "powershell.exe -Command \"Stop-Process -Name 'ping' -ErrorAction SilentlyContinue\"",
                    "elevated": "false"
                }
            ],
            "image-path": ""
        }

Start the debug stream, end it at least 3 times. By the fourth time it ends, Sunshine will be unable to execute any commands (command, detached, do, undo, does not matter) because of error code -1073741801

When putting this error code through the Windows Error Lookup, this implies it is a memory problem (page file ran out) however I have adjusted my page file to 80GB in size and the issue still remains and is persistent.

There is no solution other than rebooting the sunshine service.

Expected Behavior

That it does not permanently break until you restart the Sunshine process.

Additional Context

Desktop (with prep commands disabled) works in this state still.

Host Operating System

Windows

Operating System Version

11

Architecture

64 bit

Sunshine commit or version

0.20

Package

Linux - AppImage

GPU Type

Nvidia

GPU Model

4090

GPU Driver/Mesa Version

536.67

Capture Method (Linux Only)

No response

Config

min_log_level = 1
nv_rc = vbr
channels = 2

Apps

No response

Relevant log output

[2023:07:18:20:56:12]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:12]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 24316
[2023:07:18:20:56:12]: Warning: Return code [1]
[2023:07:18:20:56:12]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:12]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 3876
[2023:07:18:20:56:12]: Warning: Return code [1]
[2023:07:18:20:56:12]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:12]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 23652
[2023:07:18:20:56:12]: Warning: Return code [1]
[2023:07:18:20:56:12]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:12]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 25320
[2023:07:18:20:56:12]: Warning: Return code [1]
[2023:07:18:20:56:12]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:12]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:12]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 25888
[2023:07:18:20:56:13]: Warning: Return code [1]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 17736
[2023:07:18:20:56:13]: Warning: Return code [1]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 26040
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 8920
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 25400
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 23604
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 12572
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 14220
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 26596
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 3332
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 25456
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 16564
[2023:07:18:20:56:13]: Warning: Return code [-1073741801]
[2023:07:18:20:56:13]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Debug: Resolved executable [powershell.exe] to path ["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"]
[2023:07:18:20:56:13]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:18:20:56:13]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 20024
[2023:07:18:20:56:14]: Warning: Return code [-1073741801]
@Nonary Nonary added bug Something isn't working os:Windows:10 os:Windows OS is Windows labels Jul 25, 2023
@Xythus
Copy link
Contributor

Xythus commented Jul 31, 2023

Can confirm this happens on my machine as well.

Windows 10 x64 19045.3208
Sunshine 0.20.0.4b986b26c2c921b57b4ab300b002bb9e97e14c93

[2023:07:31:12:56:07]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:07]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 31224
[2023:07:31:12:56:07]: Warning: Return code [1]
[2023:07:31:12:56:07]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:07]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 30296
[2023:07:31:12:56:07]: Warning: Return code [1]
[2023:07:31:12:56:07]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:07]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 8948
[2023:07:31:12:56:07]: Warning: Return code [1]
[2023:07:31:12:56:07]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:07]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 1592
[2023:07:31:12:56:07]: Warning: Return code [1]
[2023:07:31:12:56:07]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:07]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:07]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 10180
[2023:07:31:12:56:08]: Warning: Return code [1]
[2023:07:31:12:56:08]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:08]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 27776
[2023:07:31:12:56:08]: Warning: Return code [1]
[2023:07:31:12:56:08]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:08]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 21688
[2023:07:31:12:56:08]: Warning: Return code [1]
[2023:07:31:12:56:08]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:08]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 10448
[2023:07:31:12:56:08]: Warning: Return code [1]
[2023:07:31:12:56:08]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:08]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 20840
[2023:07:31:12:56:08]: Warning: Return code [1]
[2023:07:31:12:56:08]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:08]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:08]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 23444
[2023:07:31:12:56:09]: Warning: Return code [1]
[2023:07:31:12:56:09]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:09]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 12424
[2023:07:31:12:56:09]: Warning: Return code [1]
[2023:07:31:12:56:09]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:09]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 22296
[2023:07:31:12:56:09]: Warning: Return code [1]
[2023:07:31:12:56:09]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:09]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 13396
[2023:07:31:12:56:09]: Warning: Return code [1]
[2023:07:31:12:56:09]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:09]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 2988
[2023:07:31:12:56:09]: Warning: Return code [1]
[2023:07:31:12:56:09]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:09]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:09]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 4240
[2023:07:31:12:56:10]: Warning: Return code [1]
[2023:07:31:12:56:10]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:10]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:10]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:10]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 20756
[2023:07:31:12:56:10]: Warning: Return code [-1073741801]
[2023:07:31:12:56:10]: Debug: Parsed executable [powershell.exe] from command [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:10]: Debug: Resolved executable [powershell.exe] to path ["c:\windows\system32\windowspowershell\v1.0\powershell.exe"]
[2023:07:31:12:56:10]: Info: Executing Undo Cmd: [powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue"]
[2023:07:31:12:56:10]: Info: powershell.exe -Command "Stop-Process -Name 'ping' -ErrorAction SilentlyContinue" running with PID 21180
[2023:07:31:12:56:10]: Warning: Return code [-1073741801]

@kirksaunders
Copy link
Contributor

Also seeing this issue. My repro case is:

Global prep:

global_prep_cmd = [{"do":"cmd /C \"echo global_do\"","undo":"cmd /C \"echo global_undo\"","elevated":"false"}]

App:

        {
            "name": "Test",
            "cmd": "cmd /C \"timeout /t 5\"",
            "prep-cmd": [
                {
                    "do": "cmd /C \"echo do\"",
                    "undo": "cmd /C \"echo undo\"",
                    "elevated": "false"
                }
            ],
            "image-path": ""
        }

The first 6 times I stream this "game", it works just fine. The 7th time, it fails. Afterwards, all prep/global prep commands fail. In a more complicated example (python script prep command), I'm getting the same exit code as reported above: "-1073741801". According to this source, this exit code is an out of memory error. I've confirmed via Process Explorer that none of the prep commands are being left behind after they run. But maybe Sunshine is somehow leaking child process memory?

Restarting Sunshine allows another 6 runs, until a restart is needed again. This is consistent.

Windows 10 Pro Build 19045.3208.
Sunshine Nightly Version 0.20.0.3fee592669ffa04edbaf37e6722aef39ffaf8f51

@kirksaunders
Copy link
Contributor

kirksaunders commented Aug 10, 2023

As a workaround, I wrote the following python script to restart Sunshine every 3 streams. It's not ideal, but it does prevent Sunshine from locking up.

import argparse
import os
import pathlib
import subprocess
import sys
import time
import win32serviceutil # requires pywin32 from pip

# The number of streams after which to restart Sunshine. If you have a large number of prep commands,
# you may need to decrease this.
CONSECUTIVE_STREAMS = 3
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
MEMORY_PATH = os.path.join(SCRIPT_DIR, '.memory')

def read_memory() -> int:
    if not os.path.isfile(MEMORY_PATH):
        return 0

    return int(pathlib.Path(MEMORY_PATH).read_text().strip())

def write_memory(value: int):
    with open(MEMORY_PATH, 'w') as file:
        print(value, file=file)

def normal_handler():
    count = read_memory() + 1
    if count >= CONSECUTIVE_STREAMS:
        # Wait sufficiently long for other undo scripts to finish, and for the stream to end.
        time.sleep(5)

        win32serviceutil.RestartService('Sunshine Service')
        write_memory(0)
    else:
        write_memory(count)

def detached_handler():
    # Spawn background process to restart Sunshine. This will allow Sunshine to finish up the stream before we restart it
    detached_flags = 0x00000008
    subprocess.Popen([sys.executable, __file__, 'normal'], creationflags=detached_flags)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        prog='Sunshine Restarter',
        description=f"This script is used to restart Sunshine after {CONSECUTIVE_STREAMS} consecutive streams. This is to work around a bug where prep commands will fail after running so many times."
    )
    subparsers = parser.add_subparsers(required=True, help='What action to take.')

    normal_parser = subparsers.add_parser('normal', help='Normal mode. Will restart Sunshine if consecutive stream count has been reached.')
    normal_parser.set_defaults(handler=normal_handler)

    detached_parser = subparsers.add_parser('detached', help='Detached mode. Will spawn detached process to do the restart. This is so the stream can finish up before we restart.')
    detached_parser.set_defaults(handler=detached_handler)

    args = parser.parse_args()
    args.handler()

It should be run as a global undo prep command:

{"do":"","undo":"<path to python exe> <path to where you saved the script> detached","elevated":"true"}

@kirksaunders
Copy link
Contributor

This seems related to the environment block that is passed into CreateProcessAsUserW:

      ec = impersonate_current_user(user_token, [&]() {
        std::wstring env_block = create_environment_block(env);
        ret = CreateProcessAsUserW(user_token,
          NULL,
          (LPWSTR) wcmd.c_str(),
          NULL,
          NULL,
          !!(startup_info.StartupInfo.dwFlags & STARTF_USESTDHANDLES),
          creation_flags,
          env_block.data(), // here
          start_dir.empty() ? NULL : start_dir.c_str(),
          (LPSTARTUPINFOW) &startup_info,
          &process_info);
      });

If I pass a NULL environment block instead (that is, just let it inherit from Sunshine's process), I'm unable to reproduce the issue. I don't see anything wrong with the implementation, at least according to all of the documentation and code examples I've read online.

As a test, I wrote an implementation that does the following instead of passing an environment block:

  1. Get copy of current process's (Sunshine service) environment block.
  2. Create a copy of the block from 1, and append our extra desired environment variables.
  3. Set the environment variables of the current process to the block from 2.
  4. Create child process.
  5. Reset the environment block of the current process to the block from 1.

This method also fails after the same number of prep command executions. The return code this time is 259 (ERROR_NO_MORE_ITEMS: No more data is available.), and I see Warning: System: Not enough space in Sunshine logs. I also see that the environment block failed to set, but there's no useful error from GetLastError.

@Nonary
Copy link
Collaborator Author

Nonary commented Aug 14, 2023

@kirksaunders Good find, I believe I found a fix and submitted a PR. Can you test and confirm for me?

@kirksaunders
Copy link
Contributor

kirksaunders commented Aug 14, 2023

@Nonary Thanks to your PR I found the root cause:

      // For the PATH variable, we will merge the values together
      if (boost::iequals(env_name, "PATH")) {
        env[env_name] = env_val + ";" + env[env_name].to_string();
        BOOST_LOG(info) << "PATH now has size = " << env[env_name].to_string().size();
      }

Since env is a member variable of process, it's shared across executions of prep commands. In the first execution, env["PATH"] doesn't exist. So env["PATH"] becomes <system-path>;. In the next execution, env["PATH"] exists. So this piece of code means that env["PATH"] becomes <system-path>;<system-path>;. And so on.

A quick debug log to show the length of env["PATH"] proves this:

[2023:08:13:22:36:17]: Info: PATH now has size = 1997
[2023:08:13:22:36:18]: Info: PATH now has size = 3097
[2023:08:13:22:36:18]: Info: PATH now has size = 4197
[2023:08:13:22:36:18]: Info: PATH now has size = 5297
[2023:08:13:22:36:18]: Info: PATH now has size = 6397
...

Your change remedies this, but in turn breaks the path concatenation. I think the proper solution here is to make env immutable, and refactor to do:

  1. Either: Make merge_user_environment_block return a new environment, rather than modifying env.
  2. Or: Skip creation of a boost environment and go straight to an environment block string.

I can take up this task, or feel free to do so if you want.

Related bug: the error code when running undo commands is in the wrong scope (source). This means that one undo command that fails with an error code causes all following undo commands to fail. This error code should be instantiated/declared inside of the for loop, so that each undo command starts with an empty error code object. Might as well include this fix too.

@Nonary
Copy link
Collaborator Author

Nonary commented Aug 14, 2023

@kirksaunders

Another option would be just assigning a new variable without using &, and having boost clone the environment via its copy constructor.

I tried that on my PR and that seemed to work as well.

@Nonary Nonary added the fixed This issue has been fixed and will be available in the next release. label Aug 17, 2023
@LizardByte-bot
Copy link
Member

This issue has been fixed and will be available in the next release.

@ReenigneArcher ReenigneArcher mentioned this issue Sep 13, 2023
7 tasks
@ReenigneArcher ReenigneArcher removed the bug Something isn't working label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed This issue has been fixed and will be available in the next release. os:Windows OS is Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants