fabric8-analytics-vscode-extension icon indicating copy to clipboard operation
fabric8-analytics-vscode-extension copied to clipboard

[BUG] Connection fail when using behing a corporate proxy (request to https://rhda.rhcloud.com/api/v4/analysis failed, reason: read ECONNRESET)

Open pgcalixto opened this issue 1 year ago • 7 comments
trafficstars

Describe the bug I'm behing a corporate proxy and the RHDA plugin in VSCode always fails to connect to Red Hat server, with the following message:

request to https://rhda.rhcloud.com/api/v4/analysis failed, reason: read ECONNRESET

I tried setting the proxy with all of the common procedures, such as:

  • setting http_proxy and https_proxy environment variables
  • setting VSCode's http.proxy option
  • setting VSCode's "http.proxySupport": "on" option
  • setting VSCode's http.proxyAuthorization option

None of them worked. Other plugins that need an Internet connection work with any of these settings.

To Reproduce Steps to reproduce the behavior:

  1. Open VSCode with any Java project using Maven. I used a simple hello world project (check the files below)
  2. Open pom.xml file in the editor. When doing this, RHDA starts running
  3. The error is shown in the bottom right corner (see screenshots)

Files:

  • src/main/java/HelloWorld.java:

    import org.apache.commons.lang3.StringUtils;
    
    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World!");
            System.out.println(StringUtils.capitalize("hello world!"));
        }
    }
    
  • pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.example</groupId>
        <artifactId>hello-world</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <properties>
            <java.version>21</java.version>
            <maven.compiler.source>${java.version}</maven.compiler.source>
            <maven.compiler.target>${java.version}</maven.compiler.target>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.14.0</version>
            </dependency>
        </dependencies>
    </project>
    

Expected behavior

RHDA plugin is expected to use the environment variables and/or VSCode settings to connect successfully through a corporate proxy, or to provide settings that can be customized to allow this connection.

Screenshots

image

Logs If applicable, attach logs.

VSCode(please complete the following information):

  • OS: Windows 10 Version 22H2 Build number 19045.4291
  • VSCode version: 1.89.0
  • Dependency Analytics Version: 0.9.1

Additional context Add any other context about the problem here.

pgcalixto avatar May 16 '24 17:05 pgcalixto

Hi @pgcalixto, Thank you for reaching out to us regarding this issue. Could you please attempt the solution proposed in the following issue #671?

IlonaShishov avatar May 21 '24 12:05 IlonaShishov

@IlonaShishov, I tried to set the NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable in different ways, adding it to the Windows system variables, setting it using the Powershell set command and the GUI Bash / Cygwin export key=val command, and the error persists.

pgcalixto avatar May 21 '24 15:05 pgcalixto

Hi @pgcalixto Did you check if your corporate proxy machine not blocking ( via firewall or any equivalent software/hardware component) this server -> rhda.rhcloud.com on port 443 ( or according to your policy maybe you need to explicitly allow outbound and inbound access to/from any host on a given port) ? please check to quicky see if the connection is open, and if you have telnet utility installed there - kindly run the command from your corporate proxy machine

telnet rhda.rhcloud.com 443

zvigrinberg avatar Jul 09 '24 07:07 zvigrinberg

Closing this issue due to no further comments. Please reopen this issue if still relevant.

IlonaShishov avatar Jul 31 '24 11:07 IlonaShishov

Hi! Sorry for the delay. I just upgraded the extension to v0.9.5, and it still produces the same error:

image

I was able to connect to the rhda.rhcloud.com domain, as @zvigrinberg asked:

image

@IlonaShishov, I tried to reopen the issue but wasn't able to.

pgcalixto avatar Jul 31 '24 17:07 pgcalixto

But now I was able to dig in closer. I tried to analyze the extension code and found out that it uses a "Red-Hat Dependency Analytics Exhort JavaScript API" dependency to call the RHDA API.

By inspecting this part of the Exhort JS API code in the link below, I noticed that it uses Node's Undici fetch API to make the request:

https://github.com/RHEcosystemAppEng/exhort-javascript-api/blob/27b0d2ef68e329cecd9a4150a68c23b81558db07/src/analysis.js#L32-L40

Undici fetch does not use any proxy by default, that's the reason the RHDA extension doesn't support proxies nor the environment variables HTTP_PROXY and HTTPS_PROXY, which are a community standard.

I extracted the analysis function from the link above to a local code snippet and used axios to make the same request, but with a proxy set, and it worked!

From what I'm searching, Undici has recently developed the proxy funcionality:

  • https://github.com/nodejs/undici/issues/1650
  • https://github.com/nodejs/undici/pull/2994
  • https://undici.nodejs.org/#/docs/api/ProxyAgent?id=example-basic-proxy-request-with-global-agent-dispatcher
  • https://undici.nodejs.org/#/docs/best-practices/proxy

Would there be any interest in the extension supporting this? A lot of companies have their networks behind a corporate proxy. I believe the code would have to be changed not in this repo, but in the linked Export JS API function.

pgcalixto avatar Jul 31 '24 17:07 pgcalixto

Hi @pgcalixto ,

Thanks for digging into this and finding a workaround! What you’ve pointed out about the Undici fetch API and proxy support is very interesting. We’ll look into this and see if we can prioritize it for future updates.

IlonaShishov avatar Aug 01 '24 05:08 IlonaShishov