github / gh-net

A network bridge between a Codespace and a local machine.
https://github.com/github/gh-net
286 stars 22 forks source link

Error running gh net #45

Open purkhusid opened 2 years ago

purkhusid commented 2 years ago

If I run the following command:

RUST_BACKTRACE=full gh net

I get the following output:

No such file or directory (os error 2)
thread 'main' panicked at 'byte index 50 is out of bounds of `[error] No such file or directory (os error 2)`', library/core/src/str/mod.rs:107:9
stack backtrace:
   0:     0x7f0b0c48aded - std::backtrace_rs::backtrace::libunwind::trace::h4357556c585d650a
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0b0c48aded - std::backtrace_rs::backtrace::trace_unsynchronized::h154a98bf0ddedacd
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0b0c48aded - std::sys_common::backtrace::_print_fmt::h2979687f6ef1950e
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f0b0c48aded - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h32d04e59e827f4fb
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f0b0c4cf3fc - core::fmt::write::hc90753bb4142f112
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1197:17
   5:     0x7f0b0c483b21 - std::io::Write::write_fmt::ha52e2782f4a3bd92
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/mod.rs:1672:15
   6:     0x7f0b0c48c565 - std::sys_common::backtrace::_print::h036f40a453c9603b
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f0b0c48c565 - std::sys_common::backtrace::print::h967f2f389d0661f9
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f0b0c48c565 - std::panicking::default_hook::{{closure}}::hb0388c1054df5ebe
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:295:22
   9:     0x7f0b0c48c286 - std::panicking::default_hook::hb4a5679f0641e8af
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:314:9
  10:     0x7f0b0c48caf6 - std::panicking::rust_panic_with_hook::h55da91f28ae9c97c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:698:17
  11:     0x7f0b0c48c9e7 - std::panicking::begin_panic_handler::{{closure}}::ha6d5d75e3abde1ad
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:588:13
  12:     0x7f0b0c48b2a4 - std::sys_common::backtrace::__rust_end_short_backtrace::hae84a849d394aed2
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x7f0b0c48c719 - rust_begin_unwind
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
  14:     0x7f0b0bd8e9e3 - core::panicking::panic_fmt::hf5f62850456bf94c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
  15:     0x7f0b0c4d2a4b - core::str::slice_error_fail_rt::h209ea8b1e9574487
  16:     0x7f0b0c4c7fe7 - core::ops::function::FnOnce::call_once::h39bb1d595b287a4c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  17:     0x7f0b0c4cccb8 - core::intrinsics::const_eval_select::hf6a35724d00b7aa8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/intrinsics.rs:2376:5
  18:     0x7f0b0bd8ec52 - core::str::slice_error_fail::h0c238fcd6cd41b03
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/str/mod.rs:86:9
  19:     0x7f0b0be4894f - <gh_extension::github_error::GitHubError as core::convert::Into<telemetry::telemetry::telemetry_result::TelemetryResult>>::into::hd215faeb8e78ab9c
  20:     0x7f0b0be2a753 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hd7aa05f256baee6c
  21:     0x7f0b0bdf06ad - std::thread::local::LocalKey<T>::with::hfa73588cd36c2f49
  22:     0x7f0b0be13a4f - tokio::park::thread::CachedParkThread::block_on::h3d6224b551d4090f
  23:     0x7f0b0bde5bed - tokio::runtime::thread_pool::ThreadPool::block_on::hd18f00791db81270
  24:     0x7f0b0bdc9e9e - tokio::runtime::Runtime::block_on::hfa66f810111fd82c
  25:     0x7f0b0bdaf44b - gh_extension::main::h842a827e1fc4b8f2
  26:     0x7f0b0bdefbb3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h8f84f524fb700b96
  27:     0x7f0b0bdb8439 - std::rt::lang_start::{{closure}}::ha1d41616dc8cc109
  28:     0x7f0b0c47c892 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h9b744c0fefdc9393
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:280:13
  29:     0x7f0b0c47c892 - std::panicking::try::do_call::h59d084564bdc9764
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  30:     0x7f0b0c47c892 - std::panicking::try::h2fac5eedc085d56a
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  31:     0x7f0b0c47c892 - std::panic::catch_unwind::h9421814242205f2b
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  32:     0x7f0b0c47c892 - std::rt::lang_start_internal::{{closure}}::h8a22d2e3a34292ac
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:128:48
  33:     0x7f0b0c47c892 - std::panicking::try::do_call::h1de2ec4bfbe13450
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  34:     0x7f0b0c47c892 - std::panicking::try::hcd7e19b491fbdedd
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  35:     0x7f0b0c47c892 - std::panic::catch_unwind::he7eb357483743dba
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  36:     0x7f0b0c47c892 - std::rt::lang_start_internal::h37683b205c9af4e4
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:128:20
  37:     0x7f0b0bdaf532 - main
legomushroom commented 2 years ago

@purkhusid this is indeed a confusing error message. I suspect this happens due to failing gh codespace select GH CLI command. Mind trying to run gh-net with a Codespace name to confirm that?

For instance:

gh net --codespace legomushroom-utils-rs-9qpr7qvcxwqr
komazarari commented 1 year ago

Hi, I face the same issue. In my environment, gh cs select works fine but gh net --codespace xxxx exit with the same error and backtraces.

❯ gh cs select
? Choose codespace: komazarari/foobar (master*): refactored guide
komazarari-refactored-guide-wv7gp6967jfg6rx

❯ RUST_BACKTRACE=full gh net --codespace komazarari-refactored-guide-wv7gp6967jfg6rx

No such file or directory (os error 2)
thread 'main' panicked at 'byte index 50 is out of bounds of `[io-error] No such file or directory (os error 2)`', library/core/src/str/mod.rs:107:9
stack backtrace:
...
( all backtraces are the same except hex addresses )
❯ uname -srmo && grep VERSION= /etc/os-release && gh version && gh extension list
Linux 5.15.74.2-microsoft-standard-WSL2 x86_64 GNU/Linux
VERSION="20.04.5 LTS (Focal Fossa)"
gh version 2.20.2 (2022-11-15)
https://github.com/cli/cli/releases/tag/v2.20.2
gh net  github/gh-net  v0.12.4
legomushroom commented 1 year ago

@komazarari @purkhusid the issue mind be is that the Linux will use root user for gh-net (we esalate to root automatically to be able to bind to network interfaces) and gh-net is not authenticated for the root user (to check run sudo gh auth status).

To fix this:

  1. Get your current token. Run gh auth status -t and copy token from the output.
  2. Authenticate root user with the token: echo {TOKEN} | sudo gh auth login --with-token
  3. Try the gh net again.

Sorry for the confusing, we should definitely improve the error message in this case. I will keep this issue open to track the work to be done for that.

Related issue on the GH CLI side: https://github.com/cli/cli/issues/5456

If the above does not work for you for some reason. Try connecting to the Codespace with `ssh`: ```shell $ sudo gh cs ssh ``` We rely on the GH CLI `ssh` tunnel to connect to a Codespace, so if that works, you should also be able to use the `gh-net` just fine.
komazarari commented 1 year ago

@legomushroom Thank you for your clear explanation. My environment needed a few additional fixes, but finally, I got them working fine. In my case, I installed gh with linuxbrew, so I need to install the gh-net extension for the root as well.

❯ sudo /home/linuxbrew/.linuxbrew/bin/gh auth status
github.com
  ✓ Logged in to github.com as komazarari (oauth_token)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: *******************

❯ sudo /home/linuxbrew/.linuxbrew/bin/gh net'
unknown command "net" for "gh"

Usage:  gh <command> <subcommand> [flags]

Available commands:
  alias
  api
...
...

❯ gh extension list
gh net  github/gh-net  v0.12.4
❯ sudo /home/linuxbrew/.linuxbrew/bin/gh extension list
no installed extensions found

So I installed the extension for root user as followings, then it worked well. Thank you 😃

❯ sudo /home/linuxbrew/.linuxbrew/bin/gh extension install github/gh-net'
✓ Installed extension github/gh-net

❯ sudo bash -c 'PATH=$PATH:/home/linuxbrew/.linuxbrew/bin gh net'
? Choose codespace:  [Use arrows to move, type to filter]
> komazarari/foobar (master*): refactored guide
Manamama commented 1 year ago

Yes, it works now. Another tip to troubleshoot, if needed:

sudo -i as then, after some auth login tricks:

~# gh auth status
github.com
  ✓ Logged in to github.com as [....]  (/root/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: ghp_************************************
  ✓ Token scopes: admin:org, admin:public_key, codespace, delete:packages, delete_repo, notifications, project, read:ssh_signing_key, read:user, repo, workflow, write:packages
~# gh extension install github/gh-net
✓ Installed extension github/gh-net

etc.