Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using scp to transfer a file to Coder workspace succeeds but returns non-zero exit code #5038

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

Closed
kconley-sq opened this issue Nov 12, 2022 · 5 comments · Fixed by #5044
Closed
Assignees
Labels
cli Area: CLI

Comments

@kconley-sq
Copy link
Contributor

Version: v0.11.0+df89e2c

I noticed this behavior when a shell function I wrote to automate transferring some files to my workspace via scp was failing early since I execute set -e in that function. When I re-ran scp with -v to get more details, I saw this in the output:

...
<filename elided>                                                          100%  444     9.9KB/s   00:00
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2600, received 1916 bytes, in 0.4 seconds
Bytes per second: sent 6979.1, received 5143.1
debug1: Exit status -1
@bpmct
Copy link
Member

bpmct commented Nov 12, 2022

Hmm... I was not able to reproduce this on Coder v0.11.0 or latest (v0.12.6). I also tried:

  • copying directory
  • Linux client (Debian 11, OpenSSH_8.4p1)

Is there anything else about your scp environment that may be out of the ordinary?

$ ssh -V
OpenSSH_8.6p1, LibreSSL 3.3.6
$ coder version
Coder v0.11.0+df89e2c Tue Oct 25 14:33:37 UTC 2022
https://github.com/coder/coder/commit/df89e2c3b01e3b5838d72f6a8659a116d44712a6
$ scp file.txt coder.wohoo:/home/coder/
file.txt                     100%    6     4.4KB/s   00:00    
$ echo $?
0
Verbose `scp` logs
$ scp -rv idk coder.wohoo:/root/idk
Executing: program /usr/bin/ssh host coder.wohoo, user (unspecified), command scp -v -r -t /root/idk
OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/benpotter/.ssh/config
debug1: Reading configuration data /Users/benpotter/.colima/ssh_config
debug1: /Users/benpotter/.ssh/config line 34: Applying options for coder.wohoo
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Executing proxy command: exec /usr/local/bin/coder --global-config "/Users/benpotter/Library/Application Support/coderv2" ssh --stdio wohoo
debug1: identity file /Users/benpotter/.ssh/id_rsa type 0
debug1: identity file /Users/benpotter/.ssh/id_rsa-cert type -1
debug1: identity file /Users/benpotter/.ssh/id_dsa type -1
debug1: identity file /Users/benpotter/.ssh/id_dsa-cert type -1
debug1: identity file /Users/benpotter/.ssh/id_ecdsa type -1
debug1: identity file /Users/benpotter/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/benpotter/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/benpotter/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/benpotter/.ssh/id_ed25519 type -1
debug1: identity file /Users/benpotter/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/benpotter/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/benpotter/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/benpotter/.ssh/id_xmss type -1
debug1: identity file /Users/benpotter/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version Go
debug1: compat_banner: no match: Go
debug1: Authenticating to coder.wohoo:22 as 'benpotter'
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-rsa SHA256:kilZBn34OyN51Roq7t0h33VfuCOd1Bw0r8USBAl0ENo
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
Warning: Permanently added 'coder.wohoo' (RSA) to the list of known hosts.
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/benpotter/.ssh/id_rsa RSA SHA256:6udyLPM53Bpv4b5cSNb2tB8hq/N/wasp3jKAWqYYDq4
debug1: Will attempt key: /Users/benpotter/.ssh/id_dsa 
debug1: Will attempt key: /Users/benpotter/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/benpotter/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /Users/benpotter/.ssh/id_ed25519 
debug1: Will attempt key: /Users/benpotter/.ssh/id_ed25519_sk 
debug1: Will attempt key: /Users/benpotter/.ssh/id_xmss 
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentication succeeded (none).
Authenticated to coder.wohoo (via proxy).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: proc
debug1: Sending environment.
debug1: channel 0: setting env LANG = "en_US.UTF-8"
debug1: Sending command: scp -v -r -t /root/idk
Entering directory: D0755 0 idk
Sink: D0755 0 idk
Sending file modes: C0644 6 file.txt
Sink: C0644 6 file.txt
file.txt                       0%    0     0.0KB/s   --:-- ETAscp: debug1: fd 0 clearing O_NONBLOCK
file.txt                     100%    6     5.3KB/s   00:00    
Entering directory: D0755 0 folder
Sink: D0755 0 folder
Sending file modes: C0644 0 idk.txt
Sink: C0644 0 idk.txt
idk.txt                      100%    0     0.0KB/s   00:00    scp: debug1: fd 0 clearing O_NONBLOCK

Sink: E
Sink: E
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Transferred: sent 2132, received 2092 bytes, in 0.0 seconds
Bytes per second: sent 120092.4, received 117839.2
debug1: Exit status 0
Linux Verbose
root@coder-v2:~# scp -v wget-log coder.wohoo:/root
Executing: program /usr/bin/ssh host coder.wohoo, user (unspecified), command scp -v -t /root
OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n  15 Mar 2022
debug1: Reading configuration data /root/.ssh/config
debug1: /root/.ssh/config line 10: Applying options for coder.wohoo
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Executing proxy command: exec /usr/bin/coder --global-config /root/.config/coderv2 ssh --stdio wohoo
debug1: identity file /root/.ssh/id_rsa type 0
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u1
debug1: Remote protocol version 2.0, remote software version Go
debug1: no match: Go
debug1: Authenticating to coder.wohoo:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:kilZBn34OyN51Roq7t0h33VfuCOd1Bw0r8USBAl0ENo
Warning: Permanently added 'coder.wohoo' (RSA) to the list of known hosts.
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /root/.ssh/id_rsa RSA SHA256:6udyLPM53Bpv4b5cSNb2tB8hq/N/wasp3jKAWqYYDq4
debug1: Will attempt key: /root/.ssh/id_dsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /root/.ssh/id_ed25519 
debug1: Will attempt key: /root/.ssh/id_ed25519_sk 
debug1: Will attempt key: /root/.ssh/id_xmss 
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentication succeeded (none).
Authenticated to coder.wohoo (via proxy).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: proc
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: scp -v -t /root
Sending file modes: C0644 524 wget-log
Sink: C0644 524 wget-log
wget-log                       0%    0     0.0KB/s   --:-- ETAscp: debug1: fd 0 clearing O_NONBLOCK
wget-log                     100%  524    10.0KB/s   00:00    
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Transferred: sent 2456, received 1580 bytes, in 0.3 seconds
Bytes per second: sent 8442.8, received 5431.4
debug1: Exit status 0
root@coder-v2:~# echo $?
0

@bpmct bpmct added the waiting-for-info The issue creator is asked to provide more information. label Nov 12, 2022
@kconley-sq
Copy link
Contributor Author

Thanks @bpmct for trying to reproduce it! I just noticed there is also this message in my verbose scp output (just before the file transfer progress line), and I wonder if it might be contributing to the exit code being non-zero:

scp: debug1: stat remote: No such file or directory

I didn't notice it before because it looks like this message only appears if the file I'm copying doesn't already exist in the remote destination. I was previously just re-running the scp command even though the file had already been copied at least once.

However, despite that message being shown, I confirmed the file is transferred successfully each time. 😵 And whether the file already exists at the remote destination path or not, the scp exit code continues to be 1.

Here are the versions of SSH on my local machine (macOS 13.0.1):

OpenSSH_9.0p1, LibreSSL 3.3.6

And in my Coder workspace (Ubuntu 20.04):

OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020

Also one other thing I forgot to mention is that my scp command is using a relative remote path which I think I understand should be supported in Coder 0.11.0 since it includes the fix for #4564.

@mafredri
Copy link
Member

mafredri commented Nov 13, 2022

@kconley-sq could you try running scp with the -O option? This forces legacy-SCP mode on macOS (which I'm hoping works around your issue for now). Otherwise it uses SFTP under the hood which seems to be what result in the non-zero exit code. This would explain why other systems can't reproduce the issue. I'll take a closer look at this tomorrow.

PS. More info can be discerned by adding more vs, scp -vvvvvvvv (I never remember how many is the "max" so I just slam them in there).

@mafredri mafredri self-assigned this Nov 13, 2022
@mafredri mafredri added bug cli Area: CLI labels Nov 13, 2022
mafredri added a commit that referenced this issue Nov 13, 2022
@mafredri mafredri removed the waiting-for-info The issue creator is asked to provide more information. label Nov 13, 2022
@mafredri
Copy link
Member

The fix has been merged and will be part of the next release. I tested this on macOS 13.0.1 using the built-in scp binary and exit code is correct when using this patch or the -O workaround.

@kconley-sq
Copy link
Contributor Author

Thanks @mafredri! I can confirm that adding -O to the scp command works around the issue for now. 👍

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

Successfully merging a pull request may close this issue.

3 participants