站点图标 ITGeeker技术奇客

Odoo错误修复 Exception: bus.Bus unavailable Finally fixed by ITGeeker

相信Odoo的错误Exception: bus.Bus unavailable困扰了全球太多的Odoo的开发者,因为网上一搜提问者甚多,解决方案看上去也是一堆,似乎最终失望者还是比比皆是。ITGeeker技术奇客尝试了各种办法,最终解决了这一问题,分享过程给大家,希望能帮到一些Odoo开发者节约一点时间吧

Exception: bus.Bus unavailable错误日志样例:

2023-06-06 02:45:38,198 1388075 ERROR itgeeker odoo.http: Exception during JSON request handling. 
Traceback (most recent call last):
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 624, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo13/odoo13_source/odoo/tools/pycompat.py", line 14, in reraise
    raise value
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 669, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo13/odoo13_source/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 915, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo13/odoo13_source/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo13/odoo13_source/addons/bus/controllers/main.py", line 35, in poll
    raise Exception("bus.Bus unavailable")
Exception: bus.Bus unavailable

错误分析

基本都认为是longpolling配置不正确引起的,涉及到的配置文件主要有两个:

影响的Odoo版本:

Odoo 8 | Odoo 9 | Odoo 10 | Odoo 11 | Odoo 12 | Odoo 13 | Odoo 14 | Odoo 15

Odoo 16应该不会有这个问题了,因为采用了gevent_port,直接不再使用longpolling_port端口了

网上收集的解决方案:

Nginx配置文件:

无非就是要在路径的上加上proxy_redirect off;和定义一些header,然并卵,愿意尝试的可以按照下面的代码试试看

location / {
        proxy_pass  http://backend_o13_itgeeker;
        # force timeouts if the backend dies
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        # set headers
        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto https;
    }    

location /longpolling/ {
        proxy_pass  http://backend_o13_itgeeker_chat;
        # force timeouts if the backend dies
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        # set headers
        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto https;
    }
Odoo配置文件:

要确认三个配置项,workers一定要大于等于2, 如果前端使用了Nginx或者apache,proxy_mode这里应该是True:

ODOO依赖安装

关键检查是否已安装python以下两个模块,可以用pip list | grep module_name来检查

据说没安装psycogreen的人还挺多,记得一定要安装上。

这三个方面的配置,最终的目的就是检查longpolling_port是否已正常启动?

by itgeeker.net
netstat -ntpl | grep 8372
tcp        0      0 0.0.0.0:8372            0.0.0.0:*               LISTEN      1439095/python3     
很遗憾,ITGeeker技术奇客这些都正常,longpolling_port端口也正常,但是Exception: bus.Bus unavailable还是不断的出现,真是百思不得其解。在午饭前,忽然想到,要不改一下Nginx的proxy名称,也就是这两个上游端口的名称:
# Odoo backend ##
upstream backend_o13_itgeeker {
    server 127.0.0.1:8369 weight=1 fail_timeout=3000s;
}
upstream backend_o13_itgeeker_chat {
    server 127.0.0.1:8372 weight=1 fail_timeout=3000s;
}
然后优雅的重启nginx服务nginx -s reload就去吃饭了,回来后意外发现,问题真的解决了,log不再出现Exception: bus.Bus unavailable了。希望能帮到被Odoo的这个问题困扰的你。
退出移动版