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

Doesn't work with SOCKS proxy #1769

Closed
3 tasks done
wh201906 opened this issue Dec 13, 2022 · 7 comments · Fixed by #1776
Closed
3 tasks done

Doesn't work with SOCKS proxy #1769

wh201906 opened this issue Dec 13, 2022 · 7 comments · Fixed by #1776
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@wh201906
Copy link
Contributor

wh201906 commented Dec 13, 2022

Describe the problem

I have a SOCKS proxy on port 1233 and a http proxy on port 1234. No matter which proxy type I select in Arduino IDE(SOCKS or HTTP), if I set the port to 1234, everything works fine, if I set the port to 1233, the network error occurs. It seems like the Arduino always uses the http proxy regardless of the proxy type I selected.
Plus, If I configure a http proxy in settings, it will be shown as SOCKS proxy the next time I open the Arduino IDE. But the arduino-cli.yaml still shows that it's a http proxy.

To reproduce

  1. Set a SOCKS proxy on port n and a http proxy on port n+1
  2. In Arduino, set the SOCKS proxy on port n, the network error occurs (which shows the problem)
  3. Set the http proxy on port n+1, the network works fine
  4. Set the SOCKS proxy on port n+1, the network works fine (which is unexpected)
  5. Set the http proxy on port n, the network error occurs

Expected behavior

The SOCKS proxy should work.

Arduino IDE version

Version: 2.0.3 Date: 2022-12-05T09:30:25.331Z CLI Version: 0.29.0 [76251df9] Copyright © 2022 Arduino SA

Operating system

Windows

Operating system version

Windows 10

Additional context

I have checked the proxy and I'm sure port 1233 only accepts SOCKS and 1234 only accepts http.
Both of proxy work in other apps.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@wh201906 wh201906 added the type: imperfection Perceived defect in any part of project label Dec 13, 2022
@per1234 per1234 self-assigned this Dec 14, 2022
@per1234
Copy link
Contributor

per1234 commented Dec 14, 2022

Hi @wh201906. Thanks for your report. I was not able to reproduce it.

The instructions you provided are too vague for me to be sure I am correctly reproducing what you have done. Please provide a set of very detailed and clear instructions that I can follow for a minimal reproduction of the bug and I will continue with the investigation.

@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label Dec 14, 2022
@wh201906
Copy link
Contributor Author

wh201906 commented Dec 14, 2022

Thanks for your reply. Here are the steps:

steps
  1. Set a socks proxy on 127.0.0.1:1233 and a http proxy on 127.0.0.1:1234
  2. Open Arduino IDE, go to Preferences->Network
  3. Set the proxy like this
    图片
  4. Click OK, then the net work error occurs
    图片
  5. Set the proxy like this
    图片
  6. Click OK, the IDE shows the downloading process
    图片
  7. Set the proxy like this
    图片
  8. Click OK, the IDE shows the downloading process
    图片
    This is weird because port 1234 only accepts http proxy
  9. Set the proxy like this
    图片
  10. Click OK, then the net work error occurs
    图片

(During steps 2~10, I didn't close the Arduino IDE. I just reopened the Preferences panel)

Additional information

  1. My proxy software shows the Arduino IDE is still using http proxy even if I just set a socks proxy
    图片
    图片
    图片

  2. When changing the proxy in the Arduino IDE, I can see the configuration is applied to the arduino-cli.yaml
    图片图片图片
    I guess it's something wrong in the Arduino-cli?

  3. After setting the proxy in Arduino IDE, I can't see the network config when dumping the config in arduino-cli.
    图片

Please tell me if you need more information.

@wh201906
Copy link
Contributor Author

wh201906 commented Dec 14, 2022

Plus, If I configure a http proxy in settings, it will be shown as SOCKS proxy the next time I open the Arduino IDE. But the arduino-cli.yaml still shows that it's a http proxy.

I think this is another issue. Here are the steps to reproduce it.

steps
  1. Set a socks proxy on 127.0.0.1:1233 and a http proxy on 127.0.0.1:1234
  2. Open Arduino IDE, go to Preferences->Network
  3. Set the proxy like this
    图片
  4. Click OK, the IDE shows the downloading process
    图片
  5. Go to Preferences->Network again without closing the Arduino IDE, the proxy configuration is expected
    图片
  6. Close the Arduino IDE
  7. Open arduino-cli.yaml, the proxy configuration is expected
    图片
  8. Open Arduino IDE, go to Preferences->Network, the proxy type switches from http to socks
    图片
  9. Open arduino-cli.yaml, the proxy type is still http, which doesn't match the type in Arduino IDE
    图片

@per1234 per1234 removed the status: waiting for information More information must be provided before work can proceed label Dec 15, 2022
@per1234
Copy link
Contributor

per1234 commented Dec 16, 2022

Thanks so much for that additional information @wh201906. That was very helpful. I was able to reproduce the bugs you reported here and track down the cause of the primary bug:

SOCKS Proxy Doesn't Work

  1. Click OK, then the net work error occurs
  1. Click OK, the IDE shows the downloading process
    [...]
    This is weird because port 1234 only accepts http proxy

My proxy software shows the Arduino IDE is still using http proxy even if I just set a socks proxy

I guess it's something wrong in the Arduino-cli?

Explanation

It is actually a bug in Arduino IDE that is causing all these symptoms. The problem is it uses the socks scheme in the URL when it sets the Arduino CLI proxy configuration via the network.proxy key of arduino-cli.yaml. The net/http Go package used by Arduino CLI requires the scheme to instead be socks5:

https://pkg.go.dev/net/http#Transport

I was not able to track down the code responsible for the behavior, but it seems that HTTP is used as a fallback when the scheme in the proxy URL is not recognized. This is why you found the HTTP proxy works even when you set the radio button to "SOCKS" in the Arduino IDE preferences and it sets the network.proxy key to a socks:// URL.

Workaround

  1. Open the following file in a text editor (I realize you already know where it is, but I'll provide comprehensive instructions for the benefit of any other users who might be affected):
    • If you are using Windows:
      C:\Users\<username>\.arduinoIDE\arduino-cli.yaml
      
    • If you are using Linux:
      ~/.arduinoIDE/arduino-cli.yaml
      
    • If you are using macOS:
      ~/.arduinoIDE/arduino-cli.yaml
      
  2. Change the socks:// part of the URL in the network.proxy key to socks5://
    For example, if the file contained this:
    network:
      proxy: socks://127.0.0.1:1233
    It should be changed to this:
    network:
      proxy: socks5://127.0.0.1:1233
  3. Save the file.
  4. If Arduino IDE is running, select File > Quit from the menus to close all windows.
  5. Start Arduino IDE.

Proxy Configuration Set by Arduino IDE not Shown in arduino-cli config dump Output

After setting the proxy in Arduino IDE, I can't see the network config when dumping the config in arduino-cli.

This one is normal and expected. Arduino CLI recognizes arduino-cli.yaml configuration files in several locations:

https://arduino.github.io/arduino-cli/latest/configuration/#locations

The dedicated ~/.arduinoIDE/arduino-cli.yaml file used by Arduino IDE is not in one of these locations (unless you happen to be running the arduino-cli command from that folder). So if you run arduino-cli config dump you will get the effective configuration of Arduino CLI (either the defaults, or taken from an arduino-cli.yaml file if it exists in one of the recognized locations.

You can set the location of the file via the --config-file command line flag, so if you run this command you would see the Arduino IDE configuration in the output:

arduino-cli config dump --config-file $Env:HOMEDRIVE$Env:HOMEPATH/.arduinoIDE/arduino-cli.yaml

"Preferences" Dialog Shows Incorrect Proxy Type

Open Arduino IDE, go to Preferences->Network, the proxy type switches from http to socks

I am able to reproduce this. I think it will be more effective and efficient to dedicate this issue exclusively to the incorrect socks URL scheme used when configuring Arduino CLI for a SOCKS proxy, so I have created a separate issue to track the bug with the incorrect radio button selection in the "Preferences" dialog: #1775

@per1234 per1234 added the topic: code Related to content of the project itself label Dec 16, 2022
@per1234 per1234 removed their assignment Dec 16, 2022
@wh201906
Copy link
Contributor Author

Thanks for handling these bugs!

@wh201906
Copy link
Contributor Author

The net/http Go package used by Arduino CLI requires the scheme to instead be socks5

@per1234 Hi. Can I make a PR to make a fix for it?

@per1234
Copy link
Contributor

per1234 commented Dec 16, 2022

Yes, a PR would be welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants