Code Executor 3.75.1-stable and 3.77.0-edge "Starting code executor on port NaN"

Code executor crashes on startup with the logs

Starting code executor on port NaN

Unhandled Rejection {"promise":{},"reason":{"code":"ERR_SOCKET_BAD_PORT"}}

My manifest is as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    retoolService: code-executor
  name: code-executor
spec:
  replicas: 1
  selector:
    matchLabels:
      retoolService: code-executor
  revisionHistoryLimit: 3
  template:
    metadata:
      labels:
        retoolService: code-executor
    spec:
      securityContext:
        runAsUser: 1001
        runAsGroup: 1001
        fsGroup: 1001
      containers:
        - args:
            - bash
            - start.sh
          env:
            - name: DEPLOYMENT_TEMPLATE_TYPE
              value: k8s-manifests
            - name: NODE_ENV
              value: production
            - name: NODE_OPTIONS
              value: --max_old_space_size=1024
            - name: CONTAINER_UNPRIVILEGED_MODE
              value: "true"
            - name: DISABLE_IPTABLES_SECURITY_CONFIGURATION
              value: "true"
            - name: PORT
              value: "3004"
          image: tryretool/code-executor-service:3.77.0-edge
          name: code-executor
          ports:
            - containerPort: 3004
              name: retool
              protocol: TCP
          resources:
            limits:
              cpu: 2
              memory: 4Gi
            requests:
              cpu: 1
              memory: 1Gi
          # code executor uses nsjail to sandbox code execution. nsjail requires privileged container access.
          # If your deployment does not support privileged access, you can set this to false to not use nsjail.
          # Without nsjail, all code is run without sandboxing within your deployment.
          securityContext:
            privileged: false
---
apiVersion: v1
kind: Service
metadata:
  name: code-executor
spec:
  selector:
    retoolService: code-executor
  ports:
  - protocol: TCP
    port: 3004
    targetPort: 3004
    name: http-server

I tried omitting PORT as well with the same result.

The docs around code executor environment variables are mismatched with the manifests provided @ https://github.com/tryretool/retool-onpremise/tree/master/kubernetes .

is PORT the right environment variable for code executor? Its not listed in the docs and the logs suggest it doesn't work.

is CODE_EXECUTOR_INGRESS_DOMAIN a code executor environment variable, (as the docs suggest) or is it for the other deployments to point at the code-executor service (as the retool-onpremise manifests suggest)?

The service definition for code executor is also mismatched between kubernetes and kubernetes-with-temporal (one exposes port 80 and the other 3004)

1 Like

function YV(){return parseInt(w2.default.env.CODE_EXECUTOR_PORT||"3004")}

Looking at the js it seems like the correct environment variable is CODE_EXECUTOR_PORT

I don't understand why the fallback to 3004 isn't working.

1 Like

Hey @Joe_Bernstein - welcome to the community! And thanks for reaching out.

You did some great research here - the correct environment variable is indeed CODE_EXECUTOR_PORT, but I'm similarly not sure why the fallback to 3004 isn't working. :thinking: I'll look into that a bit more and let our team know if there's a fix required.

To your second point, CODE_EXECUTOR_INGRESS_DOMAIN is an environment variable that is meant to be defined on other services, not on the code executor itself. It's obviously pertinent to setting up the code executor, which is why it's in that section of the docs, but they could definitely be a lot clearer about where the variable should actually be defined.

Last but not least, I don't know if there is a logistical reason for exposing port 80 vs 3004 on the code executor service, but I usually see 80. Both should be functional as long as you're consistent!