setup ruby/rails for debugging in Kubernetes - Puma::HttpParserError: Invalid HTTP format, parsing fails

545 Views Asked by At

I try to setup a VSCode or Intellij debugger for a Ruby on Rails API app, which runs in a Minikube Kubernetes cluster.

When I try to start the debug session, the container throws this error:

HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>

Gemfile

group :development, :test do
  gem 'debase'
  gem 'ruby-debug-ide'
end

my Dockerfile CMD:

COPY . /usr/src/app

EXPOSE 3000 1234 26162

CMD "bin/bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails server -p 3000 -b 0.0.0.0"

This is my launch.json

  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Docker",
      "type": "Ruby",
      "request": "attach",
      "remoteHost": "127.0.0.1",
      "remotePort": "1234",
      "remoteWorkspaceRoot": "/usr/src/app",
      "cwd": "${workspaceRoot}",
      "showDebuggerOutput": true
    }
]
kind: Service
metadata:
  annotations: {}
  labels:
    app: backend
  name: backend
spec:
  type: ClusterIP
  ports:
    - name: "3000"
      protocol: TCP
      port: 3000
      targetPort: 3000
    - name: "1234"
      protocol: TCP
      port: 1234
      targetPort: 1234
  selector:
    app: backend

I have also an Ingress configured.

I am able to call my app with http://localhost:1234 as well http://localhost:3000 or http://myhost.test and get a json response (as it should be).

This is the container log when I spin up a fresh container and run the VSCode debugger once: (look at the last line)

### STARTING ###
Puma starting in single mode...
* Version 3.12.6 (ruby 2.7.2-p137), codename: Llamas in Pajamas
* Min threads: 1, max threads: 1
* Environment: development
Rails Version & environment: 6.1.4.1 - development
Elastic URL credentials provided
Elasticsearch Version: {"number"=>"7.16.2", "build_flavor"=>"default", "build_type"=>"docker", "build_hash"=>"2b937c44140b6559905130a8650c64dbd0879cfb", "build_date"=>"2021-12-18T19:42:46.604893745Z", "build_snapshot"=>false, "lucene_version"=>"8.10.1", "minimum_wire_compatibility_version"=>"6.8.0", "minimum_index_compatibility_version"=>"6.0.0-beta1"}
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

2021-12-26 00:19:34 +0000: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>

Question:

  • where is my misconfiguration
  • Do I miss something?
  • Is this the right approach?
  • Do I need additional port-forwarding?
  • or some ENV_VARS?
  • Is this even possible?
1

There are 1 best solutions below

0
On

Following similar issues found here and here I can suggest the following:

  1. Clear browser cache and restart the browser.
  2. Make sure that you are using HTTP instead of HTTPS.
  3. Change to false or comment the line: config.force_ssl = true in file config/environments/production.rb.