Scoop icon indicating copy to clipboard operation
Scoop copied to clipboard

[Bug] Shim breaks interoperability between restic and rclone

Open Zottelchen opened this issue 2 years ago • 15 comments

Bug Report

Current Behavior

When attempting to use restic backups with rclone (both installed via scoop) it does not work with error messages like: Fatal: unable to open repo at rclone:onedrive:snapshot: error talking HTTP to rclone: Get "http://localhost/file-5577006791947779410": unexpected EOF

Expected Behavior

restic should be able to work, like it does with a non-scoop install.

Additional context/output

Scoop is "shimming" apps installed via https://github.com/ScoopInstaller/Shim/blob/master/src/shim.cs . However, for unknown reason, the stdin/stdout handles which should be inherited from shim process (set by restic by redirecting) aren't passed to rclone process properly if shim process is started with DETACHED_PROCESS. Even when I modified shim.cs to manually pass handles, the issue persists. I observed that a blank console window flashed which may indicate a new console was allocated.

Originally posted by @cqjjjzr in https://github.com/restic/restic/issues/3681#issuecomment-1081441509

Possible Solution

System details

Windows version: 10

OS architecture: 64bit

PowerShell version: 5.1.19041.1320

Additional software: restic, rclone

Scoop Configuration

{
    "lastupdate":  "2022-03-28T14:42:06.1230313+02:00",
    "SCOOP_REPO":  "https://github.com/lukesampson/scoop",
    "SCOOP_BRANCH":  "master"
}

Zottelchen avatar Mar 29 '22 12:03 Zottelchen

All 3 shim implementations (kiennq, 71 and C#) failed to work.

Additional information: On Windows, restic is currently creating process with DETACHED_PROCESS creation flag. Communication between rclone and restic relies on pipes, and they are established via mechanisms provided by golang. Since I'm not familiar with golang, I just did some simple digging. rclone uses STD_INPUT_HANDLE as its stdin stream. However, at the restic side, golang is using some weird way to pipe data to/from stdio streams (see https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/os/exec/exec.go;drc=refs%2Ftags%2Fgo1.18;l=244 ) and I can't figure it out completely now.

upd: As seen in https://cs.opensource.google/go/go/+/master:src/syscall/exec_windows.go;l=368 , the stdio handles are passed to child process via hStdInput, hStdOutput and hStdError fields of STARTUPINFOEX / STARTUPINFOW structure.

Therefore, it seems that shim failed to pass some sort of stdio handles to the child (rclone in this case) process.

cqjjjzr avatar Mar 29 '22 13:03 cqjjjzr

Scoop currently uses the kiennq shim by default. Can you try opening an issue about this at https://github.com/kiennq/scoop-better-shimexe?

rashil2000 avatar Mar 29 '22 13:03 rashil2000

Literally can't since issues are disabled for that repository. Hopefully, @kiennq receives notifications ;)

Zottelchen avatar Mar 29 '22 15:03 Zottelchen

I managed to pass the handles properly by modifying the shim implementation. Will open a PR in the kiennq repo later. But I noticed the kiennq repo hasn't been updated for over 1 year...

~~and the mod didn't work in restic... maybe my test is improperly written~~

~~to my great surprise, it works on my system but not in my testing virtual machine.~~

It works :) although a blank console window still appears..

cqjjjzr avatar Mar 30 '22 01:03 cqjjjzr

I noticed the kiennq repo hasn't been updated for over 1 year...

@issaclin32 should we fork the repo?

rashil2000 avatar Mar 30 '22 06:03 rashil2000

@issaclin32 should we fork the repo?

I think we should.

issaclin32 avatar Mar 30 '22 08:03 issaclin32

/cc @niheaven @rasa

rashil2000 avatar Mar 30 '22 08:03 rashil2000

Literally can't since issues are disabled for that repository. Hopefully, @kiennq receives notifications ;)

Sorry, I didn't notice the issues are being disabled on that repo. Re-enable it now

kiennq avatar Mar 30 '22 10:03 kiennq

Transfer repos to ScoopInstaller and don't change the ownership?

niheaven avatar Mar 31 '22 04:03 niheaven

Transfer repos to ScoopInstaller and don't change the ownership?

That's brilliant. I don't have permission to create public repositories on ScoopInstaller now, so how to I transfer it?

kiennq avatar Mar 31 '22 06:03 kiennq

Okay,I'll invite you as maintainer, and then you could transfer it. Please check the invitation later.

niheaven avatar Mar 31 '22 15:03 niheaven

@niheaven I still don't have permission to create a public repository on ScoopInstaller (I have merge permission, but don't have permission to create a new repository). But worry not, I've requested to transfer the kiennq/scoop-better-shimexe repo to you, so please put it to the ScoopInstaller repo later :)

kiennq avatar Apr 01 '22 13:04 kiennq

I suggest putting all shim implementations into https://github.com/ScoopInstaller/Shim so we can use CI/CD to deliver different shim binaries concurrently. If you @niheaven @kiennq agree with it, I could help to refactor code structure.

chawyehsu avatar Apr 01 '22 13:04 chawyehsu

I suggest putting all shim implementations into https://github.com/ScoopInstaller/Shim so we can use CI/CD to deliver different shim binaries concurrently. If you @niheaven @kiennq agree with it, I could help to refactor code structure.

Sure, please go ahead with that. Note that I've also added the CI/CD to my repro to automatically build and publish a new version, hope it can help with the current CI/CD

kiennq avatar Apr 01 '22 14:04 kiennq

Go ahead @chawyehsu 🎉

I'm thinking of some type of plugin system that several types of shim or other additional features should be added into Scoop Core after installation in need. The plugins are different choices or some performance improvements. I don't know if it is a good idea to be added to Scoop since this may increase some code/UX complexity.

niheaven avatar Apr 01 '22 16:04 niheaven

I seeing the same issue with terraform. no interactive input possible. ctrl+c is also not working

btw: I'm using cmder as console host with powershell v7 on windows server 2016

viceice avatar Nov 16 '22 07:11 viceice

Filing this under #1606

rashil2000 avatar Jan 07 '23 10:01 rashil2000