EXEC access from websocket

Hello,
The exec command by websocket stop working after some release.
Now I am getting:
error: Unexpected server response: 404

And in lxc monitor output:

location: none
metadata:
  context: {}
  level: debug
  message: 'Failure for websocket operation: 43bde241-c9d0-4e47-ba87-ce1a3a4944c9:
    Timed out waiting for websockets to connect'
timestamp: "2022-04-28T16:34:52.723720455+02:00"
type: logging


location: none
metadata:
  class: websocket
  created_at: "2022-04-28T16:34:47.721001378+02:00"
  description: Executing command
  err: Timed out waiting for websockets to connect
  id: 43bde241-c9d0-4e47-ba87-ce1a3a4944c9
  location: none
  may_cancel: false
  metadata:
    command:
    - top
    environment:
      FOO: BAR
      LANG: C.UTF-8
      PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
    fds:
      "0": f5da36ad2297e4fdb24f48fedbdee28c02286dde571c79dff5ad66f66623572a
      control: cbf91f3612a116ae7863e5eeb4fdd6fac3a173deeb48245e113928dbe7473a34
    interactive: true
  resources:
    containers:
    - /1.0/containers/login
    instances:
    - /1.0/instances/login
  status: Failure
  status_code: 400
  updated_at: "2022-04-28T16:34:47.721001378+02:00"
project: default
timestamp: "2022-04-28T16:34:52.724471782+02:00"
type: operation

It was working before by this test commands:
lxc query -X POST -d '{"command":["top"],"environment":{"HOME": "/root", "TERM": "xterm", "USER": "root"},"interactive":true,"wait-for-websocket":true}' /1.0/containers/login/exec

wscat -c wss://127.0.0.1:8443/1.0/operations/[ id ]/websocket?secret=[ metadata-fds-0 ] -n

How can I connect to the websocket from wscat or from javascript code? Any suggestions?

We introduced a number of timeouts which you seem to be hitting here.
@tomp would know more but I suspect you need to have things connected within 5s or so for things to behave.

You are likely not connecting to all of the websocket channels that LXD expects. Previously we didn’t check for this, but now we do. In this case you are requesting interactive mode and there are 2 channels needed, the input/output channel 0, and the control channel.

Can you confirm which websocket channels you are connecting to?

I am connecting to channel 0. So I need to connect to channel 0 and also to control channel to make websocket open? Or is there some timeout property?

You need to connect to both within 5s.

Thank you @tomp its working when I connect to both.

1 Like