Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Odoo 16 [KeyError: 'socket'] #106339

Closed
davidmonterocrespo24 opened this issue Nov 23, 2022 · 61 comments
Closed

Error in Odoo 16 [KeyError: 'socket'] #106339

davidmonterocrespo24 opened this issue Nov 23, 2022 · 61 comments

Comments

@davidmonterocrespo24
Copy link

Impacted versions: Odoo 16 Docker

Steps to reproduce:
I get the error when I install Odoo 16 via docker

File "/usr/lib/python3/dist-packages/odoo/addons/bus/controllers/websocket.py", line 23, in websocket
return WebsocketConnectionHandler.open_connection(request)
File "/usr/lib/python3/dist-packages/odoo/addons/bus/websocket.py", line 807, in open_connection
Websocket(request.httprequest.environ['socket'], request.session),
KeyError: 'socket'

@The-macharia
Copy link

This could be because you have set proxy_mode = True in your odoo config file but you're not using a reverse proxy.

@mjrk
Copy link
Contributor

mjrk commented Jan 30, 2023

I see the same error, no docker, just fresh odoo 16 run locally. Full Traceback:

Traceback (most recent call last):
  File "/home/odoo/odoo/odoo/http.py", line 1986, in __call__
    response = request._serve_db()
  File "/home/odoo/odoo/odoo/http.py", line 1579, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/odoo/odoo/odoo/service/model.py", line 134, in retrying
    result = func()
  File "/home/odoo/odoo/odoo/http.py", line 1608, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoo/odoo/odoo/http.py", line 1721, in dispatch
    return self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoo/odoo/addons/website/models/ir_http.py", line 235, in _dispatch
    response = super()._dispatch(endpoint)
  File "/home/odoo/odoo/odoo/addons/base/models/ir_http.py", line 144, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoo/odoo/odoo/http.py", line 698, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoo/odoo/addons/bus/controllers/websocket.py", line 23, in websocket
    return WebsocketConnectionHandler.open_connection(request)
  File "/home/odoo/odoo/addons/bus/websocket.py", line 814, in open_connection
    Websocket(request.httprequest.environ['socket'], request.session),
KeyError: 'socket'

proxy_mode is set to False. However, I do not get this error with proxy_mode True behind a reverse proxy on the server. Still, it is not clear how to set up the development environment correctly, or if this error can be ignored entirely. The issue appeared in Odoo 16 in - as far as I can tell - standard development configuration in comparison to Odoo 15.

@davidmonterocrespo24 davidmonterocrespo24 changed the title Error in Odoo 16 Error in Odoo 16 [KeyError: 'socket'] Jan 30, 2023
@HoangSang1510
Copy link

HoangSang1510 commented Feb 3, 2023

I see the same error, no docker, just fresh odoo 16 run locally. Full Traceback:

Traceback (most recent call last):
  File "/home/odoo/odoo/odoo/http.py", line 1986, in __call__
    response = request._serve_db()
  File "/home/odoo/odoo/odoo/http.py", line 1579, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/odoo/odoo/odoo/service/model.py", line 134, in retrying
    result = func()
  File "/home/odoo/odoo/odoo/http.py", line 1608, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoo/odoo/odoo/http.py", line 1721, in dispatch
    return self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoo/odoo/addons/website/models/ir_http.py", line 235, in _dispatch
    response = super()._dispatch(endpoint)
  File "/home/odoo/odoo/odoo/addons/base/models/ir_http.py", line 144, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoo/odoo/odoo/http.py", line 698, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoo/odoo/addons/bus/controllers/websocket.py", line 23, in websocket
    return WebsocketConnectionHandler.open_connection(request)
  File "/home/odoo/odoo/addons/bus/websocket.py", line 814, in open_connection
    Websocket(request.httprequest.environ['socket'], request.session),
KeyError: 'socket'

proxy_mode is set to False. However, I do not get this error with proxy_mode True behind a reverse proxy on the server. Still, it is not clear how to set up the development environment correctly, or if this error can be ignored entirely. The issue appeared in Odoo 16 in - as far as I can tell - standard development configuration in comparison to Odoo 15.

I have the same error. Did you know how to fix it ? Thank in advance.
p/s: This Error appear when i setting worker value in local.conf

@davidmonterocrespo24
Copy link
Author

@Yenthe666
do you know what it could be?

@zuher83
Copy link

zuher83 commented Feb 15, 2023

Check your Nginx config file.

location /websocket {
        proxy_redirect off;
        proxy_pass http://odoochat; (need upstream 127.0.0.1:8072) and not :8069 port
        }

This solved the problem for me

@majorbird-team
Copy link

Thanks @zuher83, worked for me too.

@markuskirch
Copy link

markuskirch commented Apr 12, 2023

We are running Odoo behind a traefik reverse proxy. Traefik is a great improvement over nginx for us because it allows dynamic/ container-driven routing. Switching to Nginx is no option for us.

We get this error with our Odoo 16 containers, although we already did the following steps:

  1. changed the path prefix from /longpolling/ to /websocket/. So now all requests coming in over HOST/websocket/ are forwarded to port 8072
  2. Traefik by default forwards all of the http headers: X-Forwarded-For/X-Real-IP, X-Fordwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Server (see https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests)
  3. We run Odoo in multiprocessing mode (workers > 0), and the gevent_port is not set in the config (so it defaults to 8072).

Still, we get this error.

Does anyone here have an idea how to fix this issue with Traefik reverse proxy?

@bassn
Copy link
Contributor

bassn commented Apr 16, 2023

I get this error without any reverse proxy.
I install Odoo 16 in Ubuntu WSL
The error appears if I set worker in the conf file (no matter how many: I try with 1, 2 and 3)
The error disappears i do not set worker in conf file (e.g. if comment the worker line with a ";" in the conf file)
Can someone help?

@zuher83
Copy link

zuher83 commented Apr 16, 2023

I get this error without any reverse proxy. I install Odoo 16 in Ubuntu WSL The error appears if I set worker in the conf file (no matter how many: I try with 1, 2 and 3) The error disappears i do not set worker in conf file (e.g. if comment the worker line with a ";" in the conf file) Can someone help?

This is normal, I advise you to work a proxy reverse and configure it well (eg: Nginx ...). Also configure your hosts file in Windows 11 to target the right local domain. You must also configure your network when you launch your WSL...

@oliverzgy
Copy link

We are running Odoo behind a traefik reverse proxy. Traefik is a great improvement over nginx for us because it allows dynamic/ container-driven routing. Switching to Nginx is no option for us.

We get this error with our Odoo 16 containers, although we already did the following steps:

  1. changed the path prefix from /longpolling/ to /websocket/. So now all requests coming in over HOST/websocket/ are forwarded to port 8072
  2. Traefik by default forwards all of the http headers: X-Forwarded-For/X-Real-IP, X-Fordwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Server (see https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests)
  3. We run Odoo in multiprocessing mode (workers > 0), and the gevent_port is not set in the config (so it defaults to 8072).

Still, we get this error.

Does anyone here have an idea how to fix this issue with Traefik reverse proxy?

Have you solved the issue? @markuskirch

@markuskirch
Copy link

We are running Odoo behind a traefik reverse proxy. Traefik is a great improvement over nginx for us because it allows dynamic/ container-driven routing. Switching to Nginx is no option for us.

We get this error with our Odoo 16 containers, although we already did the following steps:

  1. changed the path prefix from /longpolling/ to /websocket/. So now all requests coming in over HOST/websocket/ are forwarded to port 8072
  2. Traefik by default forwards all of the http headers: X-Forwarded-For/X-Real-IP, X-Fordwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Server (see https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests)
  3. We run Odoo in multiprocessing mode (workers > 0), and the gevent_port is not set in the config (so it defaults to 8072).

Still, we get this error.

Does anyone here have an idea how to fix this issue with Traefik reverse proxy?

Have you solved the issue? @markuskirch

@oliverzgy no, unfortunately not.

Odoo Enterprise support couldn't really help us.

The problem seems to be that not all headers are forwarded correctly by treafik in the default configuration. Odoo support couldn't really tell us which headers and header values are expected specifically, which makes troubleshooting rather difficult.

I suspect that the problem might be related to the https entrypoint, because websockets might use the ws protocol (or wss after an ssl handshake) (again: no official info which proto is used by Odoo websockets), and traefik sets the X-Forwarded-Proto value to https.
Our next step is to build additional ws and/or wss entrypoints and a middleware that re-routes all websocket traffic to these entrypoints (similar to the http entrypoint that re-routes all requests to the https entrypoint) using the correct Proto values.

In addition to the Proto, there might also be a problem with the Upgrade/Connection header. The ws/wss middleware could forward this header or set header key/value pairs manually, but again we lack information on which key and value is expected by Odoo.

Looking forward to hearing if you can make any progress with this issue.

@millmakerjm
Copy link

We had similar issues. In Odoo 16 the path /longpolling/ seems to be renamed to /websocket so without the trailing slash.

@testtrem
Copy link

the following config worked for me

upstream odoo-get {
server 127.0.0.1:8069;
}

upstream odoolp-get {
server 127.0.0.1:8072;
}

server {
server_name DOMAIN.COM;
include /etc/nginx/conf.d/common_params.conf;
include /etc/nginx/conf.d/common_proxy.conf;

location / {
add_header Access-Control-Allow-Origin *;
proxy_pass http://odoo-get;
}

location /websocket {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://odoolp-get;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/CERTF/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/CERTF/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
listen 80;
server_name DOMAIN.COM;
return 301 https://$host$request_uri;
}

where common proxy is
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Client-IP $remote_addr;
proxy_set_header HTTP_X_FORWARDED_HOST $remote_addr;
#Para time out
proxy_connect_timeout 1600;
proxy_send_timeout 1600;
proxy_read_timeout 1600;
send_timeout 1600;

and common params is
client_max_body_size 50M;

this is for an odoo running with workers 3 and proxy mode True

@testtrem
Copy link

upon revision
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

those lines are not necesary

@Pexers
Copy link

Pexers commented May 18, 2023

The problem with the NGINX proxy pass solutions is that they're only hiding the error... not actually fixing it...

@deyanira87
Copy link

We are running Odoo behind a traefik reverse proxy. Traefik is a great improvement over nginx for us because it allows dynamic/ container-driven routing. Switching to Nginx is no option for us.

We get this error with our Odoo 16 containers, although we already did the following steps:

  1. changed the path prefix from /longpolling/ to /websocket/. So now all requests coming in over HOST/websocket/ are forwarded to port 8072
  2. Traefik by default forwards all of the http headers: X-Forwarded-For/X-Real-IP, X-Fordwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Server (see https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests)
  3. We run Odoo in multiprocessing mode (workers > 0), and the gevent_port is not set in the config (so it defaults to 8072).

Still, we get this error.

Does anyone here have an idea how to fix this issue with Traefik reverse proxy?


I got same error using Traefik. In my case the problem was Ubuntu Server, I had to migrate the server to Debian 11 and now this problem in particular with others problem that I got during the use of Odoo 16 have been solved.

@bguernouti
Copy link

bguernouti commented Jun 14, 2023

I have the same problem, and when I don't specify any workers in the config, I get a lot of "connection lost. trying to reconnect"

@ale900522
Copy link

We are running Odoo behind a traefik reverse proxy. Traefik is a great improvement over nginx for us because it allows dynamic/ container-driven routing. Switching to Nginx is no option for us.

We get this error with our Odoo 16 containers, although we already did the following steps:

1. changed the path prefix from `/longpolling/` to `/websocket/`. So now all requests coming in over `HOST/websocket/` are forwarded to port `8072`

2. Traefik by default forwards all of the http headers: X-Forwarded-For/X-Real-IP, X-Fordwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Server (see https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests)

3. We run Odoo in multiprocessing mode (`workers > 0`), and the `gevent_port` is not set in the config (so it defaults to `8072`).

Still, we get this error.

Does anyone here have an idea how to fix this issue with Traefik reverse proxy?

Do you get some solution I have this problem now

@jonahbohlmann
Copy link

We are running Odoo behind a traefik reverse proxy. Traefik is a great improvement over nginx for us because it allows dynamic/ container-driven routing. Switching to Nginx is no option for us.

We get this error with our Odoo 16 containers, although we already did the following steps:

  1. changed the path prefix from /longpolling/ to /websocket/. So now all requests coming in over HOST/websocket/ are forwarded to port 8072
  2. Traefik by default forwards all of the http headers: X-Forwarded-For/X-Real-IP, X-Fordwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Server (see https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests)
  3. We run Odoo in multiprocessing mode (workers > 0), and the gevent_port is not set in the config (so it defaults to 8072).

Still, we get this error.

Does anyone here have an idea how to fix this issue with Traefik reverse proxy?

We had the same issue with traefik, but I think I could solve it.

I have this configuration in odoo.conf:

proxy_mode = True
workers = 9
max_cron_threads = 3

Setting proxy_mode to True solved the websocket error.

My traefik configuration in docker-compose:

      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.odoo.entrypoints=http"
      - "traefik.http.routers.odoo.rule=Host(`odoo.domain.de`)"
      - "traefik.http.middlewares.odoo-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.odoo.middlewares=odoo-https-redirect"
      - "traefik.http.routers.odoo-secure.entrypoints=https"
      - "traefik.http.routers.odoo-secure.rule=Host(`odoo.domain.de`)"
      - "traefik.http.routers.odoo-secure.tls=true"
      - "traefik.http.routers.odoo-secure.service=odoo"
      - "traefik.http.services.odoo.loadbalancer.server.port=8069"

Now it looks like it was working for us. Maybe there is smth that can help you too?

Version:

  • Odoo: 16.0+e-20230627
  • Traefik: v2.9.9

@ale900522
Copy link

nfiguration in docker-compose:


I have this solution and its work now, odoo 16 change correctly to websocket communication:
labels:
# # global config
- "traefik.enable=true"
- "traefik.docker.network=traefik-swarm"
# # main routers 8069 web rule "/*"
- "traefik.http.routers.${NAME_SERVICE_TRAEFIK}.tls=true"
- "traefik.http.routers.odoo16.entrypoints=https"
- "traefik.http.routers.odoo16.rule=Host(traefik.odoo16.com)"
- "traefik.http.routers.odoo16.service=odoo16@docker"
- "traefik.http.routers.odoo16.middlewares=gzip"
- "traefik.http.services.odoo16.loadbalancer.server.port=8069"
# # main routers 8072 websocket rule "/websocket"
- "traefik.http.routers.backend-websock.tls=true"
- "traefik.http.routers.backend-websock.entrypoints=https"
- "traefik.http.routers.backend-websock.rule=Path(/websocket) && Host(traefik.odoo16.com)"
- "traefik.http.routers.backend-websock.middlewares=upgradeheader,sslheader,gzip"
- "traefik.http.routers.backend-websock.service=backend-websock@docker"
- "traefik.http.services.backend-websock.loadbalancer.server.port=8072"
# # upgrade headers
- "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Upgrade=websocket"
- "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Connection=upgrade"
- "traefik.http.middlewares.upgradeheader.headers.hostsproxyheaders=websocket,Upgrade"
- "traefik.http.middlewares.upgradeheader.headers.forcestsheader=true"
- "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https"
# # gzip compress
- "traefik.http.middlewares.gzip.compress=true"

@ale900522
Copy link

nfiguration in docker-compose:


I have this solution and its work now, odoo 16 change correctly to websocket communication: labels: # # global config - "traefik.enable=true" - "traefik.docker.network=traefik-swarm" # # main routers 8069 web rule "/*" - "traefik.http.routers.${NAME_SERVICE_TRAEFIK}.tls=true" - "traefik.http.routers.odoo16.entrypoints=https" - "traefik.http.routers.odoo16.rule=Host(traefik.odoo16.com)" - "traefik.http.routers.odoo16.service=odoo16@docker" - "traefik.http.routers.odoo16.middlewares=gzip" - "traefik.http.services.odoo16.loadbalancer.server.port=8069" # # main routers 8072 websocket rule "/websocket" - "traefik.http.routers.backend-websock.tls=true" - "traefik.http.routers.backend-websock.entrypoints=https" - "traefik.http.routers.backend-websock.rule=Path(/websocket) && Host(traefik.odoo16.com)" - "traefik.http.routers.backend-websock.middlewares=upgradeheader,sslheader,gzip" - "traefik.http.routers.backend-websock.service=backend-websock@docker" - "traefik.http.services.backend-websock.loadbalancer.server.port=8072" # # upgrade headers - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Upgrade=websocket" - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Connection=upgrade" - "traefik.http.middlewares.upgradeheader.headers.hostsproxyheaders=websocket,Upgrade" - "traefik.http.middlewares.upgradeheader.headers.forcestsheader=true" - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https" # # gzip compress - "traefik.http.middlewares.gzip.compress=true"

I hope work for all guys.

@markuskirch
Copy link

Great, thanks for sharing your solution!

@imhassanawais
Copy link

imhassanawais commented Aug 14, 2023

the following config worked for me

upstream odoo-get { server 127.0.0.1:8069; }

upstream odoolp-get { server 127.0.0.1:8072; }

server { server_name DOMAIN.COM; include /etc/nginx/conf.d/common_params.conf; include /etc/nginx/conf.d/common_proxy.conf;

location / { add_header Access-Control-Allow-Origin *; proxy_pass http://odoo-get; }

location /websocket { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_pass http://odoolp-get; }

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/CERTF/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/CERTF/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server { listen 80; server_name DOMAIN.COM; return 301 https://$host$request_uri; }

where common proxy is proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Client-IP $remote_addr; proxy_set_header HTTP_X_FORWARDED_HOST $remote_addr; #Para time out proxy_connect_timeout 1600; proxy_send_timeout 1600; proxy_read_timeout 1600; send_timeout 1600;

and common params is client_max_body_size 50M;

this is for an odoo running with workers 3 and proxy mode True

this one worked for me, i have installed odoo16 in a docker behind nginx, i have been searching for days and found the only thing is how you handle proxy pass and back requests via nginx. i have multiple odoo installation so this one had odoo on 8081 and live chat/websocket on port 20025, you may replace it with 8069 and 8072 respectivly. replace xyz with your domain name.

here is my working configuration.

Odoo servers

upstream odoo {
server 127.0.0.1:8081;
}

upstream odoochat {
server 127.0.0.1:20025 weight=1 fail_timeout=0;
}

server {
server_name erp.xyz.com;

proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;

Proxy headers

proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;

log files

access_log /var/log/nginx/erp.xyz.com.access.log;
error_log /var/log/nginx/erp.xyz.error.log;

Handle longpoll requests

location /websocket {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://odoochat;
proxy_redirect off;
}

Handle / requests

location / {
proxy_redirect off;
proxy_pass http://odoo;
add_header Access-Control-Allow-Origin *;

}

Gzip

gzip_types text/css text/less text/plain text/xml application/xml application/json application/ja$
gzip on;

client_body_in_file_only clean;
client_body_buffer_size 32k;
client_max_body_size 500M;
sendfile on;
send_timeout 600s;
keepalive_timeout 300;

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/erp.xyz.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/erp.xyz.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = erp.xyz.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

server_name erp.xyz.com;
listen 80;
return 404; # managed by Certbot

}

@majorbird-team
Copy link

Thank you @imhassanawais , your solution worked for me.

I personally use docker for my odoo deployments behind nginx + nginx-letsencrypt + nginx-gen (automatic nginx configuration for new containers + automatic SSL certificates generation).
I use the containers from https://github.com/nginx-proxy/nginx-proxy and the nginx-companion etc.

For others using the same setup as mine, you may find the following instructions useful.

NGINX vhost files for odoo

Add this in your vhost file in nginx vhost conf folder (the file should have the same name as the domain you are using, example DOMAIN)
Replace CONTAINER_NAME by your container name.

## Start of configuration add by letsencrypt container
location ^~ /.well-known/acme-challenge/ {
    auth_basic off;
    auth_request off;
    allow all;
    root /usr/share/nginx/html;
    try_files $uri =404;
    break;
}
## End of configuration add by letsencrypt container

gzip_types text/css text/less text/plain text/xml application/xml application/json application/ja$
gzip on;

client_body_in_file_only clean;
client_body_buffer_size 32k;
client_max_body_size 500M;
sendfile on;
send_timeout 600s;
keepalive_timeout 300;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;

location /websocket {
    proxy_pass http://CONTAINER_NAME:8072;
    proxy_set_header Upgrade $http_upgrade;

    proxy_set_header Connection "Upgrade";
    proxy_redirect off;

    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
}

NGINX vhost location configuration

Add this in your vhost file location in nginx vhost conf folder, the filename should be DOMAIN_location

    add_header Access-Control-Allow-Origin *;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_redirect off;

ODOO configuration file

Make sure you enabled these parameters in your odoo.conf file, of course you can change the workers count.

proxy_mode = True
workers = 2

@bnisevic
Copy link

bnisevic commented Oct 6, 2023

I am also having this issue on multiple servers Ubuntu/nginx/Odoo 16. I am getting
File "/odoo/odoo-server/addons/bus/websocket.py", line 817, in open_connection
Websocket(request.httprequest.environ['socket'], request.session),
KeyError: 'socket'

I am using proxy_mode = True and this is from nginx conf:
location /websocket {
proxy_pass http://odoochat;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}

Anybody seeing something missing here?

@Julien00859
Copy link
Member

Julien00859 commented Oct 9, 2023

Did you update your dependencies via pip or apt?

@Julien00859
Copy link
Member

We improved the error reporting here #137972 hopefully this will help you understanding what's going on

@bnisevic
Copy link

Did you update your dependencies via pip or apt?

I did install fresh from the GitHub repo and ran pip install -r requirements.txt. As I understood the versions there are pinned. Also there is nothing upgradable in the Ubuntu.

Main reason why I am hunting this websockets bug is because I do not have "Tap to Scan" functionality in the Attendances Kiosk Mode. Only "Scan your badge" barcode icon is there. But no "Tap to Scan" overlay with the red line. In the Network tab on that page I see that websocket_worker_bundle?v=1.0.5 is always pending, it was not ever loaded and the size loaded is 0B. I presume this is wrong?

@jugj-odoo
Copy link
Contributor

Unfortunately fixing this error did not fix the problem with missing "Tap to Scan" in Attendances Kiosk Mode. I still have this issue: https://www.odoo.com/forum/help-1/tap-to-scan-in-attendances-kiosk-mode-does-not-work-in-community-version-16-235019

Hello @bnisevic , regarding the missing feature "Tap to scan", the barcode scanner feature was an enterprise module until version 16.2 unfortunately, so it won't be available in your community version.

@bnisevic
Copy link

Thanks guys for the help and explanations! The picture is much clearer now. I hope this thread will help other people with similar problem.

@Julien00859 gave a really nice explanation.

For sure these requests (directly to Odoo web server) were made from kiosk mode. This is where I got errors.

IMHO there should be somewhere in the documentation noted If reverse proxy is used then xmlrpc_interface should be set to the local address and not listening everywhere. This is clear to me now. But from the docs it was not clear. Odoo site is under maintenance right now, I can not access so I am putting the link blindly, I think reverse proxy conf is shown somewhere here https://www.odoo.com/documentation/16.0/administration/install.html

Now, how can I upgrade to 16.2? 😏

@RobReus
Copy link

RobReus commented Oct 28, 2023

nfiguration in docker-compose:


I have this solution and its work now, odoo 16 change correctly to websocket communication: labels: # # global config - "traefik.enable=true" - "traefik.docker.network=traefik-swarm" # # main routers 8069 web rule "/*" - "traefik.http.routers.${NAME_SERVICE_TRAEFIK}.tls=true" - "traefik.http.routers.odoo16.entrypoints=https" - "traefik.http.routers.odoo16.rule=Host(traefik.odoo16.com)" - "traefik.http.routers.odoo16.service=odoo16@docker" - "traefik.http.routers.odoo16.middlewares=gzip" - "traefik.http.services.odoo16.loadbalancer.server.port=8069" # # main routers 8072 websocket rule "/websocket" - "traefik.http.routers.backend-websock.tls=true" - "traefik.http.routers.backend-websock.entrypoints=https" - "traefik.http.routers.backend-websock.rule=Path(/websocket) && Host(traefik.odoo16.com)" - "traefik.http.routers.backend-websock.middlewares=upgradeheader,sslheader,gzip" - "traefik.http.routers.backend-websock.service=backend-websock@docker" - "traefik.http.services.backend-websock.loadbalancer.server.port=8072" # # upgrade headers - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Upgrade=websocket" - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Connection=upgrade" - "traefik.http.middlewares.upgradeheader.headers.hostsproxyheaders=websocket,Upgrade" - "traefik.http.middlewares.upgradeheader.headers.forcestsheader=true" - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https" # # gzip compress - "traefik.http.middlewares.gzip.compress=true"

I can confirm that this also worked for me. I am running Odoo as a TrueNAS App, the app itself is created/maintained by TrueCharts. Since the Traefik app in TrueCharts does not (yet) support all the required middleware types/settings, I had to apply these manually using k3s kubectl apply -f. The same goes for the extra ingress for the websocket path. I have attached my yaml files which I loaded using k3s kubectl apply -f in case someone else stumbles accross this issue that is also using TrueNAS/TrueCharts. Just make sure to edit the files to correct the domain name and other things like namespaces.
odoo-header-middleware.yaml.txt
odoo-compress-middleware.yaml.txt
odoo-ingress.yaml.txt

@VIPKaiser
Copy link

nfiguration in docker-compose:


I have this solution and its work now, odoo 16 change correctly to websocket communication: labels: # # global config - "traefik.enable=true" - "traefik.docker.network=traefik-swarm" # # main routers 8069 web rule "/*" - "traefik.http.routers.${NAME_SERVICE_TRAEFIK}.tls=true" - "traefik.http.routers.odoo16.entrypoints=https" - "traefik.http.routers.odoo16.rule=Host(traefik.odoo16.com)" - "traefik.http.routers.odoo16.service=odoo16@docker" - "traefik.http.routers.odoo16.middlewares=gzip" - "traefik.http.services.odoo16.loadbalancer.server.port=8069" # # main routers 8072 websocket rule "/websocket" - "traefik.http.routers.backend-websock.tls=true" - "traefik.http.routers.backend-websock.entrypoints=https" - "traefik.http.routers.backend-websock.rule=Path(/websocket) && Host(traefik.odoo16.com)" - "traefik.http.routers.backend-websock.middlewares=upgradeheader,sslheader,gzip" - "traefik.http.routers.backend-websock.service=backend-websock@docker" - "traefik.http.services.backend-websock.loadbalancer.server.port=8072" # # upgrade headers - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Upgrade=websocket" - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Connection=upgrade" - "traefik.http.middlewares.upgradeheader.headers.hostsproxyheaders=websocket,Upgrade" - "traefik.http.middlewares.upgradeheader.headers.forcestsheader=true" - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https" # # gzip compress - "traefik.http.middlewares.gzip.compress=true"

I'm having this issue. But this doesn't fix it. I use CloudFlare which seems to be possibly the issue. Any ideas?

@bnisevic
Copy link

nfiguration in docker-compose:


I have this solution and its work now, odoo 16 change correctly to websocket communication: labels: # # global config - "traefik.enable=true" - "traefik.docker.network=traefik-swarm" # # main routers 8069 web rule "/*" - "traefik.http.routers.${NAME_SERVICE_TRAEFIK}.tls=true" - "traefik.http.routers.odoo16.entrypoints=https" - "traefik.http.routers.odoo16.rule=Host(traefik.odoo16.com)" - "traefik.http.routers.odoo16.service=odoo16@docker" - "traefik.http.routers.odoo16.middlewares=gzip" - "traefik.http.services.odoo16.loadbalancer.server.port=8069" # # main routers 8072 websocket rule "/websocket" - "traefik.http.routers.backend-websock.tls=true" - "traefik.http.routers.backend-websock.entrypoints=https" - "traefik.http.routers.backend-websock.rule=Path(/websocket) && Host(traefik.odoo16.com)" - "traefik.http.routers.backend-websock.middlewares=upgradeheader,sslheader,gzip" - "traefik.http.routers.backend-websock.service=backend-websock@docker" - "traefik.http.services.backend-websock.loadbalancer.server.port=8072" # # upgrade headers - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Upgrade=websocket" - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Connection=upgrade" - "traefik.http.middlewares.upgradeheader.headers.hostsproxyheaders=websocket,Upgrade" - "traefik.http.middlewares.upgradeheader.headers.forcestsheader=true" - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https" # # gzip compress - "traefik.http.middlewares.gzip.compress=true"

I'm having this issue. But this doesn't fix it. I use CloudFlare which seems to be possibly the issue. Any ideas?

Did you set xmlrpc_interface in the odoo conf?

@VIPKaiser
Copy link

Yes I set that. I've tried absolutely everything. Spent many hours now trying to get this to work. :-(

@bnisevic
Copy link

Yes I set that. I've tried absolutely everything. Spent many hours now trying to get this to work. :-(

You should checkout the console in your browser and see on which address are you getting the key error.

@VIPKaiser
Copy link

Bad Request
Empty or missing header(s): sec-websocket-key, connection, sec-websocket-version, origin, upgrade.

In the logs it says 400 Bad Request: Empty or missing header(s).

@bnisevic
Copy link

Bad Request Empty or missing header(s): sec-websocket-key, connection, sec-websocket-version, origin, upgrade.

In the logs it says 400 Bad Request: Empty or missing header(s).

This does not sound as the same KeyError issue mentioned above. But it sounds like a problem with the Cloudflare.

@Majestic7979
Copy link

nfiguration in docker-compose:


I have this solution and its work now, odoo 16 change correctly to websocket communication: labels: # # global config - "traefik.enable=true" - "traefik.docker.network=traefik-swarm" # # main routers 8069 web rule "/*" - "traefik.http.routers.${NAME_SERVICE_TRAEFIK}.tls=true" - "traefik.http.routers.odoo16.entrypoints=https" - "traefik.http.routers.odoo16.rule=Host(traefik.odoo16.com)" - "traefik.http.routers.odoo16.service=odoo16@docker" - "traefik.http.routers.odoo16.middlewares=gzip" - "traefik.http.services.odoo16.loadbalancer.server.port=8069" # # main routers 8072 websocket rule "/websocket" - "traefik.http.routers.backend-websock.tls=true" - "traefik.http.routers.backend-websock.entrypoints=https" - "traefik.http.routers.backend-websock.rule=Path(/websocket) && Host(traefik.odoo16.com)" - "traefik.http.routers.backend-websock.middlewares=upgradeheader,sslheader,gzip" - "traefik.http.routers.backend-websock.service=backend-websock@docker" - "traefik.http.services.backend-websock.loadbalancer.server.port=8072" # # upgrade headers - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Upgrade=websocket" - "traefik.http.middlewares.upgradeheader.headers.customRequestHeaders.Connection=upgrade" - "traefik.http.middlewares.upgradeheader.headers.hostsproxyheaders=websocket,Upgrade" - "traefik.http.middlewares.upgradeheader.headers.forcestsheader=true" - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https" # # gzip compress - "traefik.http.middlewares.gzip.compress=true"

Thanks for this. I was able to make live chat work. It is VERY IMPORTANT to observe the ORDER of the rule below:

Path(/websocket) && Host(traefik.odoo16.com) = it works
Host(traefik.odoo16.com) && Path(/websocket) = it DOES NOT work.

So the path has to come first. Otherwise it simply doesn't function.

In my case, I had to configure with www and without www so mine looks like this:

Path(/websocket) && Host(www.mydomain.com) || Host(mydomain.com) = live chat works

Previous it was like this:

Host(www.mydomain.com) || Host(mydomain.com) && Path(/websocket) = it was not working.

So again, PATH HAS TO COME BEFORE HOST. I did not know that Traefik v2 cared about the order. Now I do. Thanks for the above solution!

@xra-devops
Copy link

xra-devops commented Nov 20, 2023

Question: our QA server is running without NginX reverse proxy and we are getting the "KeyError: 'socket'" error. If my understanding of this thread is correct, the error is caused by a reverse proxy/ odoo misconfiguration, how do we resolve this issue if we are not using a reverse proxy? Why are these errors occurring if there is no reverse proxy? Thanks in advance!!

Running on (stock standard) Ubuntu 20.04

Config:
[options]
(...)
db_host = False
db_port = False
db_user = odoo
db_password = False
default_productivity_apps = True
logfile = /var/log/odoo/odoo.log
limit_memory_soft = 7039797760
limit_memory_hard = 8247757312
limit_request = 16384
limit_time_cpu = 1800
limit_time_real = 3600
max_cron_threads = 2
workers = 8
proxy_mode = False

@VIPKaiser
Copy link

Question: our QA server is running without NginX reverse proxy and we are getting the "KeyError: 'socket'" error. If my understanding of this thread is correct, the error is caused by a reverse proxy/ odoo misconfiguration, how do we resolve this issue if we are not using a reverse proxy? Why are these errors occurring if there is no reverse proxy? Thanks in advance!!

Running on (stock standard) Ubuntu 20.04

Config: [options] (...) db_host = False db_port = False db_user = odoo db_password = False default_productivity_apps = True logfile = /var/log/odoo/odoo.log limit_memory_soft = 7039797760 limit_memory_hard = 8247757312 limit_request = 16384 limit_time_cpu = 1800 limit_time_real = 3600 max_cron_threads = 2 workers = 8 proxy_mode = False

Are you forwarding websockets to 8072?

@pomazanbohdan
Copy link

pomazanbohdan commented Feb 28, 2024

  • "traefik.http.routers. backend-websock.rule=Path( /websocket) && Host( traefik.odoo16.com)"

Need add ` in url

- "traefik.http.routers.backend-websock.rule=Path(`/websocket`) && Host(`traefik.odoo16.com`)" 

After that, the internal error about the socket in docker disappeared

@krptg0
Copy link

krptg0 commented Feb 29, 2024

I've concatenated every snipper for traefik from this thread, and I'm not having the KeyError error, but rather a 404 error on /websockets, answered by worker "longpolling". Anyone had the same ?

2024-02-29 12:17:56,182 24 INFO ? longpolling: 1.1.1.1 - - [2024-02-29 12:17:56] "GET /websocket HTTP/1.1" 404 356 0.013499

@pomazanbohdan
Copy link

pomazanbohdan commented Feb 29, 2024

I've concatenated every snipper for traefik from this thread, and I'm not having the KeyError error, but rather a 404 error on /websockets, answered by worker "longpolling". Anyone had the same ?

2024-02-29 12:17:56,182 24 INFO ? longpolling: 1.1.1.1 - - [2024-02-29 12:17:56] "GET /websocket HTTP/1.1" 404 356 0.013499

longpolling_port = False
gevent_port=8072

in odoo.conf?

@krptg0
Copy link

krptg0 commented Feb 29, 2024

@pomazanbohdan yup, that's the odoo.conf :

[options]
addons_path = /mnt/enterprise-addons
admin_passwd = blablabla
limit_time_cpu = 86400
limit_time_real = 86400
proxy_mode = True
limit_memory_soft = 13538884000
limit_memory_hard = 140388840001
longpolling_port = False
gevent_port = 8072
workers = 4
max_cron_threads = 1
data_dir = /var/lib/odoo

@ale900522
Copy link

@pomazanbohdan yup, that's the odoo.conf :

[options]
addons_path = /mnt/enterprise-addons
admin_passwd = blablabla
limit_time_cpu = 86400
limit_time_real = 86400
proxy_mode = True
limit_memory_soft = 13538884000
limit_memory_hard = 140388840001
longpolling_port = False
gevent_port = 8072
workers = 4
max_cron_threads = 1
data_dir = /var/lib/odoo

if you use docker-compose add this soluction in your labels in compose #106339 (comment)

@pomazanbohdan
Copy link

image
Make sure that the rule is working correctly in Traefik

@ale900522
Copy link

image Make sure that the rule is working correctly in Traefik

Im sure, Its working for me now, let me send you a picture

@ale900522
Copy link

image Make sure that the rule is working correctly in Traefik

Im sure, Its working for me now, let me send you a picture
Screenshot_20240229_181510

@ale900522
Copy link

ale900522 commented Feb 29, 2024

image Make sure that the rule is working correctly in Traefik

Im sure, Its working for me now
But when you call domain/websocket the response is Bad request becouse this request is manage by odoo internal
in your service logs you need find code HTTP 101 when you receive code 101 its work perfectly

@Joybaruah
Copy link

Joybaruah commented Mar 1, 2024

the following config worked for me
upstream odoo-get { server 127.0.0.1:8069; }
upstream odoolp-get { server 127.0.0.1:8072; }
server { server_name DOMAIN.COM; include /etc/nginx/conf.d/common_params.conf; include /etc/nginx/conf.d/common_proxy.conf;
location / { add_header Access-Control-Allow-Origin *; proxy_pass http://odoo-get; }
location /websocket { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_pass http://odoolp-get; }

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/CERTF/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/CERTF/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server { listen 80; server_name DOMAIN.COM; return 301 https://$host$request_uri; }
where common proxy is proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Client-IP $remote_addr; proxy_set_header HTTP_X_FORWARDED_HOST $remote_addr; #Para time out proxy_connect_timeout 1600; proxy_send_timeout 1600; proxy_read_timeout 1600; send_timeout 1600;
and common params is client_max_body_size 50M;
this is for an odoo running with workers 3 and proxy mode True

this one worked for me, i have installed odoo16 in a docker behind nginx, i have been searching for days and found the only thing is how you handle proxy pass and back requests via nginx. i have multiple odoo installation so this one had odoo on 8081 and live chat/websocket on port 20025, you may replace it with 8069 and 8072 respectivly. replace xyz with your domain name.

here is my working configuration.

Odoo servers

upstream odoo { server 127.0.0.1:8081; }

upstream odoochat { server 127.0.0.1:20025 weight=1 fail_timeout=0; }

server { server_name erp.xyz.com;

proxy_read_timeout 720s; proxy_connect_timeout 720s; proxy_send_timeout 720s;

Proxy headers

proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr;

log files

access_log /var/log/nginx/erp.xyz.com.access.log; error_log /var/log/nginx/erp.xyz.error.log;

Handle longpoll requests

location /websocket { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_pass http://odoochat; proxy_redirect off; }

Handle / requests

location / { proxy_redirect off; proxy_pass http://odoo; add_header Access-Control-Allow-Origin *;

}

Gzip

gzip_types text/css text/less text/plain text/xml application/xml application/json application/ja$ gzip on;

client_body_in_file_only clean; client_body_buffer_size 32k; client_max_body_size 500M; sendfile on; send_timeout 600s; keepalive_timeout 300;

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/erp.xyz.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/erp.xyz.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server { if ($host = erp.xyz.com) { return 301 https://$host$request_uri; } # managed by Certbot

server_name erp.xyz.com; listen 80; return 404; # managed by Certbot

}

Not working in my case
odoo configuration

workers = 8
max_cron_threads = 2
xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1
proxy_mode = True
gevent_port = 8072
logfile = /var/log/odoo/odoo.log

NGINX configuration

server {
   listen 443;
   server_name erp.example.info;

   proxy_read_timeout 720s;
   proxy_connect_timeout 720s;
   proxy_send_timeout 720s;


   proxy_set_header X-Forwarded-Host $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Real-IP $remote_addr;

   access_log /var/log/nginx/erp.eeki.info.access.log;
   error_log /var/log/nginx/erp.eeki.info.error.log;


  location / {
	proxy_set_header X-Forwarded-Host $http_host;
    	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect off;
        proxy_pass http://odoo;
	# Enable HSTS
   	add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
  }

  location /websocket {
	proxy_pass http://odoochat;
	proxy_set_header Upgrade $http_upgrade;
    	proxy_set_header Connection $connection_upgrade;
    	proxy_set_header X-Forwarded-Host $http_host;
    	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	proxy_set_header X-Forwarded-Proto $scheme;
    	proxy_set_header X-Real-IP $remote_addr;
  }

  gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
  gzip on;

  client_body_in_file_only clean;
  client_body_buffer_size 32k;
  client_max_body_size 500M;
  sendfile on;
  send_timeout 600s;
  keepalive_timeout 300;
}

Is any configuration missing here?

@Julien00859
Copy link
Member

Julien00859 commented Mar 2, 2024

We are closing this issue because the root cause of the KeyError: "socket" issue has been established. Your odoo server is running in multi-processing (--workers) mode and an extra dedicated gevent server has been automatically started on an alternative port (8072 by default). All websocket requests must be redirected/proxied to that extra gevent server with the two Connection and Upgrade headers set by a web server. It seems that this web server is missing / unused / mis-configured.

Using the feedback from this issue, we tried to improve the official documentation regarding the system configuration. The builtin server section have been entirely reworded with up-to-date termonology. The HTTPS section has been updated with websocket sample configuration for nginx (don't forget the map block!). The Serving static files and attachments is new (from 16.0).

Can I use Odoo without a reverse proxy?

This address a question from @xra-devops.

No, the internal Odoo web server is not suited to face the internet. We are using the same technology as flask does: werkzeug, a a library that offers many http-related utilities including a light web server that is:

not designed to be particularly efficient, stable, or secure.1

While we tweaked that server to offers efficiency and stability, we didn't wasted our time securing it because that's actually the job of the web server to filter and sanitize incoming requests. Running the Odoo web server in front of the internet makes you vulnerable to numerous threats, DOS attacks on top of them.

We recommend nginx because that's the web server we know best.

Can I use Odoo without the --workers option?

Running Odoo without the --workers options starts the multi-threaded (development) server instead of the multi-processing (production) one. While you technically can, this is not recommended. Doc

Can I use Odoo with traefic, or any other web server, instead of nginx?

This address a question from many of you.

I personally never used traefic so I cannot answer the question. If it is a robust reverse-proxy that offers all the features required by Odoo then I guess it is.

Your web server must:

  • Be the sole entity capable of accessing the Odoo web server. This is done with --http-interface (when running on the same machine) or a firewall (when running on another one). Doc
  • Only answer to HTTPS requests. Clear HTTP requests should be redirected on the HTTPS port of the web server. Doc
  • Terminates the TLS trafic, i.e. it listens the internet in HTTPS but talk to the odoo web server in HTTP. Doc
  • Serves static files. Doc.
  • Proxies dynamic requests (=requests that are not static) to the Odoo web server. On the --http-port or on the --gevent-port depending on the request path and your server mode (more below). Doc
  • Repeat the Connection and Upgrade HTTP headers from the original (internet) websocket request onto the proxied (odoo) websocket request. Those two headers are defined by the HTTP RFC to be hop-by-hop23 i.e. all intermediary proxies ought to remove them by default but they must be conserved in this case.

The actual port on which to redirect /websocket depends on the server mode you're using. It is --gevent-port when using the multi-processing server. It is --http-port when using the multi-threaded server. Doc. Repeating the Connection and Upgrade HTTP header is compulsory no matter which server mode you're using!

The logs are not helping me debug the problem!

I personally use mitm-proxy to debug all my problems regarding http. It is a proxy that you start in between your web server and Odoo and that is going to log every request and response. Much like the network tab of the chrome dev tools... but server side.

I start mitm-proxy in reverse mode twice, once 8080->8069 and once 8081->8072

$ mitmproxy --listen-host 127.0.0.1 --listen-port 8080 --mode reverse:http://127.0.0.1:8069 --set keep_host_header  # regular
$ mitmproxy --listen-host 127.0.0.1 --listen-port 8081 --mode reverse:http://127.0.0.1:8072 --set keep_host_header  # websocket

I then change the nginx configuration to proxy the regular trafic on port 8080 (instead of 8069) and websocket trafic on port 8081 (instead of 8072).

I then verify that every request correctly show up on the correct interface. I also verify that every mandated header is present.

Websocket still isn't working!

Better not ask it here and ping the 28 people who are still subscribed. Please open another issue and ping @odoo/rd-http on it. We'll have a look.

Footnotes

  1. https://werkzeug.palletsprojects.com/en/3.0.x/serving/#werkzeug.serving.run_simple

  2. https://httpwg.org/specs/rfc9110.html#field.connection

  3. https://httpwg.org/specs/rfc9110.html#field.upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests