che icon indicating copy to clipboard operation
che copied to clipboard

che-theia cannot create Che API REST Client

Open anselmov opened this issue 6 years ago • 9 comments

Describe the bug

After a workspace using che-theia is started, projects/tasks views are empty and che-theia pod logs show:

root ERROR Security problem: Unable to configure separate webviews domain: Error: Unable to get workspace containers. Cause: Cannot create Che API REST Client

The issue is similar to #15923 but there is no log spam.

I run che in a corporate k8s cluster but I would appreciate any advice on how to configure this client.

Che version

  • [x] latest

Steps to reproduce

Same as #15923 but I create a workspace with che-theia:next as editor.

Runtime

  • [X] kubernetes

Installation method

  • [X] helm
multiuser: true
serverStrategy: single-host
tls:
  enabled: true
  useSelfSignedCerts: true

Environment

corporate k8s cluster

Additional context

ERROR logs from console:

base.ts:91 HEAD https://static.developers.redhat.com/che/theia_artifacts/theia.be44868926a89c2fa5cf.js 404
url @ base.ts:91
(anonymous) @ base.ts:66
buildScripts @ base.ts:66
(anonymous) @ ?uid=247115:9
logger-protocol.ts:112 root ERROR Failed to get remote terminal server api end point url. Cause:  Error: Request 'findTerminalServer' failed
    at Proxy.<anonymous> (https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1361193)
    at Object.<anonymous> (https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1517420)
    at https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1515233
    at Object.next (https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1515338)
    at https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1514250
    at new Promise (<anonymous>)
    at SRfV.i (https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1514024)
    at n.termApiEndPointProvider (https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1517192)
    at n.<anonymous> (https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:2871290)
    at https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:2870383

Note: https://che-host-8080.company.com/server86wur4bb-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js is a working url

full ERROR logs from che-theia pod:

Unable to create Che API REST Client: "CHE_WORKSPACE_TELEMETRY_BACKEND_PORT" is not set.
root ERROR Security problem: Unable to configure separate webviews domain:  Error: Unable to get workspace containers. Cause: Cannot create Che API REST Client
    at CheApiServiceImpl.<anonymous> (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:292:31)
    at step (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:38:23)
    at Object.throw (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:19:53)
    at rejected (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:11:65)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
root ERROR Uncaught Exception:  [object Object]
root ERROR Failed to load plugin dependencies from '/plugins/installed.json' path Error: ENOTDIR: not a directory, open '/plugins/installed.json/package.json'
root ERROR Failed to load plugin dependencies from '/plugins/sidecars' path Error: ENOENT: no such file or directory, open '/plugins/sidecars/package.json'
root ERROR Request findTerminalServer failed with error: Unable to get list workspace containers. Cause: [object Object] Error: Unable to get list workspace containers. Cause: [object Object]
    at CHEWorkspaceServiceImpl.<anonymous> (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:127:31)
    at step (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:64:23)
    at Object.throw (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:45:53)
    at rejected (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:37:65)
root ERROR Request findTerminalServer failed with error: Unable to get list workspace containers. Cause: [object Object] Error: Unable to get list workspace containers. Cause: [object Object]
    at CHEWorkspaceServiceImpl.<anonymous> (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:127:31)
    at step (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:64:23)
    at Object.throw (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:45:53)
    at rejected (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:37:65)
root ERROR Request findTerminalServer failed with error: Unable to get list workspace containers. Cause: [object Object] Error: Unable to get list workspace containers. Cause: [object Object]
    at CHEWorkspaceServiceImpl.<anonymous> (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:127:31)
    at step (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:64:23)
    at Object.throw (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:45:53)
    at rejected (/home/theia/node_modules/@eclipse-che/theia-terminal/lib/node/workspace-service-impl.js:37:65)
root ERROR Request getUserPreferences failed with error: Protocol "http:" not supported. Expected "https:" 
root ERROR Request getUserPreferences failed with error: Protocol "http:" not supported. Expected "https:" 
root ERROR Failed to get remote terminal server api end point url. Cause:  Error: Request 'findTerminalServer' failed
    at Proxy.<anonymous> (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1361193)
    at Object.<anonymous> (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1517420)
    at https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1515233
    at Object.next (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1515338)
    at https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1514250
    at new Promise (<anonymous>)
    at SRfV.i (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1514024)
    at n.termApiEndPointProvider (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:1517192)
    at n.<anonymous> (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:2871290)
    at https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:2870383
root ERROR Could not start contribution TypeError: Cannot read property 'breakpointsEnabled' of null
    at t.<anonymous> (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:568943)
    at https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:562534
    at Object.next (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:562639)
    at a (https://che-host-8080.company.com/serverli5pujem-jwtproxy/server-4401/theia.be44868926a89c2fa5cf.js:1:561382)

anselmov avatar Feb 18 '20 14:02 anselmov

@azatsarynnyy please have a look

l0rd avatar Feb 19 '20 07:02 l0rd

Hello @anselmov what the version of eclipse/che-plugin-registry image you're using?

Most likely eclipse/che-theia:next isn't compartible with you version of eclipse/che-plugin-registry. It's better to use both next images.

azatsarynnyy avatar Feb 20 '20 14:02 azatsarynnyy

Hi @azatsarynnyy

So I upgraded from eclipse/che-plugin-registry:latest (7.8.0) to eclipse/che-plugin-registry:next and I still get the same errors.

Should https://github.com/eclipse/che-plugin-registry/blob/master/v3/plugins/eclipse/che-theia/next/meta.yaml provide env value CHE_WORKSPACE_TELEMETRY_BACKEND_PORT ?

anselmov avatar Feb 21 '20 13:02 anselmov

Hello @azatsarynnyy @anselmov , still getting the same error: sudo: setrlimit(RLIMIT_CORE): Operation not permitted Unable to create Che API REST Client: "CHE_WORKSPACE_TELEMETRY_BACKEND_PORT" is not set.

We are using version 7.16.1

DarthBlair avatar Aug 20 '20 08:08 DarthBlair

Hello @DarthBlair is it just an error reported or does it prevents Che from functioning normally. Asking because I see that setting CHE_WORKSPACE_TELEMETRY_BACKEND_PORT is optional. Not setting it means disabled telemetry.

azatsarynnyy avatar Aug 20 '20 14:08 azatsarynnyy

@azatsarynnyy I am not shure about that.. we deployed che in an air gapped eviroment. After Starting a workspace everything is normal, until the theia container starts. Nothing is changing (no editor window), still th loading screen. In the end there is a timeout where the workspace is stopped:

Started container maven
Container image
"harbor..../eclipse/che-sidecar-java:11-f76ca45" already present on machine Created container vscode-javaemr Started container vscode-javaemr Container image "harbor..../eclipse/che-machine-exec:7.16.1"
already present on machine
Created container che-machine-execms3
Started container che-machine-execms3
Container image "harbor..../eclipse/che-theia:7.16.1"
already present on machine
Created container theia-idegok
Started container theia-idegok
Error: Failed to run the workspace: "Server 'theia' in container 'theia-idegok' not available."

DarthBlair avatar Aug 20 '20 16:08 DarthBlair

According to the logs from che-theia pod, we have almost the same problem. We tried to deploy che in our k8s cluster behind a proxy server, then we get the same log as shown above.

Short Version

In a short word, it is a bug that the dependency axios 0.19.0 of @eclipse/che-workspace-client can not handle the environment variable NO_PROXY properly when it contains subdomain matching patterns. Upgrading to axios 0.20.0 and rebuilding it solved our problem.

Long Story of Analysis

The first error gives messages like this.

root ERROR Security problem: Unable to configure separate webviews domain:  Error: Unable to get workspace containers. Cause: Cannot create Che API REST Client
    at CheApiServiceImpl.<anonymous> (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:292:31)
    at step (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:38:23)
    at Object.throw (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:19:53)
    at rejected (/home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js:11:65)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

We try to get more detailed informations about /home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js in this container. After reading the source code, we decide to add some console.log in the following function to find out why it can not access the API endpoint.

CheApiServiceImpl.prototype.updateAndGetRemoteAPI = function (userToken) {
        return workspace_client_1.default.getRestApi({
            baseUrl: this.baseAPIUrl,
            ssCrtPath: che_https_1.SS_CRT_PATH,
            machineToken: userToken && userToken.length > 0 ? undefined : this.machineToken,
            userToken: userToken && userToken.length > 0 ? userToken : undefined
        });
    };

So, we set the following variables in the ConfigMap of che, for forcing k8s to use a local image instead of downloading from internet if it is just found locally.

  CHE_WORKSPACE_PLUGIN__BROKER_PULL__POLICY: IfNotPresent
  CHE_WORKSPACE_SIDECAR_IMAGE__PULL__POLICY: IfNotPresent
  CHE_INFRA_KUBERNETES_PVC_JOBS_IMAGE_PULL__POLICY: IfNotPresent

Then, we overide the Docker image locally use the following Dockerfile.

FROM quay.io/eclipse/che-theia:7.18.1
 
USER root
 
# add console.log around the line who throws exceptions
RUN sed -i 's#return workspace_client_1.default.getRestApi({#console.log(this.baseAPIUrl);console.log(che_https_1.SS_CRT_PATH);console.log(userToken);console.log(this.machineToken);return workspace_client_1.default.getRestApi({loggingEnabled:true,#g' /home/theia/node_modules/@eclipse-che/theia-plugin-ext/lib/node/che-api-service.js

The output shows that all parameters are correct as expected. We need dive deeper into the source code.

The function workspace_client_1.default.getRestApi is actually from package @eclipse/che-workspace-client, we read its source code directly. It is a package using axios library to making API requests.

The function getRestApi is in index.ts, and we added lots of console.log in this file for more details. Nothing happened but we noticed that addLogInterceptorsIfEnabled add two interceptors around the axios doing a request, however only one of them before request is called. Some uncaught exceptions thrown in axios, so that the invoking is terminated abnormally!

By the way, the following line

root ERROR Uncaught Exception:  [object Object]

is printed by the interceptor, which is terrible to print an object directly without serialization. [object Object] is no help for debugging.

Thus, we try to locate the uncaught exception at first. In the che-theia container, we use node inspect to debug it just as the following.

bash-5.0$ ps
PID   USER     TIME  COMMAND
    1 root      0:00 {entrypoint.sh} /bin/bash /entrypoint.sh
   21 root      0:10 node src-gen/backend/main.js /projects --hostname=127.0.0.1 --port=3100
   33 root      0:01 /usr/local/bin/node /home/theia/node_modules/@theia/core/lib/node/messaging/ipc-bootstrap.js --nsfwOptions={}
   50 root      0:00 /usr/local/bin/node /home/theia/node_modules/@eclipse-che/theia-remote/lib/node/plugin-host-custom.js
   57 root      0:00 bash
   64 root      0:00 node inspect -p 21
   72 root      0:00 bash
   78 root      0:00 ps
bash-5.0$ node inspect -p 21
debug> breakOnException
debug>
break in _http_client.js:152
 150
 151   if (protocol !== expectedProtocol) {
>152     throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
 153   }
 154
debug> list()
 147     if (INVALID_PATH_REGEX.test(path))
 148       throw new ERR_UNESCAPED_CHARACTERS('Request path');
 149   }
 150
 151   if (protocol !== expectedProtocol) {
>152     throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
 153   }
 154
 155   const defaultPort = options.defaultPort ||
 156                     (this.agent && this.agent.defaultPort);
 157
debug> exec('path')
'https://<url of che>/api/activity/workspace9qn06uhsxpbzcxeb'
debug> exec('protocol')
'http:'
debug> exec('expectedProtocol')
'https:'
debug> backtrace
#0 ClientRequest _http_client.js:152:4
#1 request http.js:46:9
#2 p._performRequest /home/theia/node_modules/@eclipse-che/workspace-client/dist/server.js:1:54763
#3 p /home/theia/node_modules/@eclipse-che/workspace-client/dist/server.js:1:52672
#4 u.request /home/theia/node_modules/@eclipse-che/workspace-client/dist/server.js:1:53105
#5 (anonymous) /home/theia/node_modules/@eclipse-che/workspace-client/dist/server.js:29:30682
#6 e.exports /home/theia/node_modules/@eclipse-che/workspace-client/dist/server.js:29:28707
#7 e.exports /home/theia/node_modules/@eclipse-che/workspace-client/dist/server.js:29:32537

It is releated to something like the following two messages in log. (Of course, the Request maybe different)

root ERROR Request getUserPreferences failed with error: Protocol "http:" not supported. Expected "https:" 
root ERROR Request getUserPreferences failed with error: Protocol "http:" not supported. Expected "https:" 

Here, @eclipse-che/workspace-client/dist/server.js is a packed file including @eclipse/che-workspace-client and its dependecies.

According to the backtrace, the call stack is like:

@eclipse/che-workspace-client
--> axios (http.js)
--> follow-redirects
--> nodejs built-in http module  <-- Uncaught Exception occurs (_http_client.js)

We added lots of console.log in @eclispe/che-workspace-client/node_moudules/axios/lib/adapters/http.js and finally we found out some logic is wrong.

        if (noProxyEnv) {
          var noProxy = noProxyEnv.split(',').map(function trim(s) {
            return s.trim();
          });

          shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
            if (!proxyElement) {
              return false;
            }
            if (proxyElement === '*') {
              return true;
            }
            if (proxyElement[0] === '.' &&
              parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement &&
              proxyElement.match(/\./g).length === parsed.hostname.match(/\./g).length) {
              return true;
            }

            return parsed.hostname === proxyElement;
          });
        }

The condition proxyElement.match(/\./g).length === parsed.hostname.match(/\./g).length will failed if you use subdomain matching in NO_PROXY.

Due to this bug, some settings for proxy server is mixed in accidentally, and finally it raise a protocol mismatch error when doing a native http request.

In our deployment, we patched it and all works fine now.

Furthermore, this bug is already patched in axios 0.20.0 as the following URL shows. https://github.com/axios/axios/commit/85c9d4ffb093debaca82f76377f102ab2af913cb

Unfortunately, @eclipse/che-workspace-client is still use axios 0.19.0. We hope @eclipse/che-workspace-client can update its dependencies as soon as possible.

d-tsu avatar Sep 23 '20 01:09 d-tsu

Hello @d-tsu that's a great investigation and analysis!

Will you be able to propose a corresponding patch to the related repos?

  • https://github.com/eclipse/che-workspace-client
  • https://github.com/eclipse/che-theia

azatsarynnyy avatar Sep 23 '20 19:09 azatsarynnyy

@azatsarynnyy I suppose there is no need to patch to Che-theia. "@eclipse-che/workspace-client": "latest" is defined in extensions/eclipse-che-theia-remote-api/package.json .

monaka avatar Nov 02 '20 07:11 monaka