github / gh-copilot

Ask for assistance right in your terminal.
https://docs.github.com/en/copilot/github-copilot-in-the-cli
713 stars 31 forks source link

[BUG]: Receiving connection refused in Termux #48

Open Shamikoh opened 6 months ago

Shamikoh commented 6 months ago

Thanks for taking the time to fill out this out! :bow: By submitting this issue, you agree to follow our Code of Conduct.

What happened?

What did you do? What happened? What did you expect to happen?

This error below is thrown to stdout when using gh copilot commands in Termux terminal emulator on Android

✗ Error: failed to create thread: error sending request: error making request: Post "https://api.githubcopilot.com/github/chat/threads": dial tcp: lookup api.githubcopilot.com on [::1]:53: read udp [::1]:39758->[::1]:53: read: connection refused

Versions

What versions of the relevant software are you running? For example: gh v2.37.0, gh-copilot v0.5.2-beta

gh version 2.46.0 https://github.com/cli/cli/releases/tag/v2.46.0

gh copilot version 1.0.0 (2024-03-18)

Relevant terminal output

Please copy and paste any relevant terminal output. Please check your output before submission to ensure sensitive information is redacted.

Screenshot_2024-03-22-11-07-28-209_com termux-edit

williammartin commented 6 months ago

Can you run the same command with GODEBUG=netdns=2 in your environment on? I suspect there's something funny happening here around Go's DNS resolution.

williammartin commented 6 months ago

Related comment from the CLI: https://github.com/cli/cli/issues/5723#issuecomment-1141469170

Shamikoh commented 6 months ago

Can you run the same command with GODEBUG=netdns=2 in your environment on? I suspect there's something funny happening here around Go's DNS resolution.

Sure, here it is Screenshot_2024-03-26-12-52-21-030_com termux

williammartin commented 6 months ago

So I can see from your output that you are using the built in Go DNS resolver. I think you're running into this upstream lack of support for binaries compiled without cgo for Android: https://github.com/golang/go/issues/8877

Right now I'm not really sure what we can do about this on our end. The workarounds on that issue seem to be "patch Go itself" or "point the net Dialer at a specific DNS server". Need to think about this.

niten94 commented 3 weeks ago

I do not use AI but I saw that this issue was linked with golang/go#8877. I tried reading details about why localhost DNS server is used and writing about it in a comment in another repository, but I do not want to try advertising it. I was thinking some parts of the comment may be relevant as a workaround:

/etc/resolv.conf is usually used when targetting Linux. The DNS server listening at UDP port 53 on IPv6 localhost is probably used when the file cannot be used, but a DNS server is not usually run. Go programs in Termux packages target Android and use $PREFIX/etc/resolv.conf in resolv-conf package. I do not think it will be much useful distributing executable files targetting Android upstream, but proot can be used like this:

pkg install proot resolv-conf
proot -b $PREFIX/etc/resolv.conf:/etc/resolv.conf gh copilot ...

I do not know if a built version of golang package in Termux can be used without a mobile device when distributing executable files targetting Termux upstream. I tried searching a bit but I have not seen Copilot being requested to be distributed as a package in official repository and Termux User Repository yet.