odoo-jsonrpc icon indicating copy to clipboard operation
odoo-jsonrpc copied to clipboard

Remaining connection slots are reserved for non-replication superuser connections

Open SwiTool opened this issue 5 months ago • 2 comments

Regularily I get these error messages :

Odoo Server Error: FATAL: remaining connection slots are reserved for non-replication superuser connections

It is triggered by a queue worker in Laravel Horizon.

I need to either :

  • restart the odoo database
  • restart the queue worker to make it work again.

Maybe there's some documentation issue on how to properly terminate a connection ?

Here's a code example on what's causing the issue :

        dispatch(function () use ($lead) {
            $odoo = app(Odoo::class);
            $odoo->createOrUpdateContact($lead->user);

            $data = array_merge(LeadDto::fromLead($lead), [
                'stage_id' => config('odoo.stages.qualified'),
                'partner_id' => $lead->user->odoo_partner_id,
            ]);

            $lead->odoo_lead_id = $odoo->rpc->model('crm.lead')->create($data);
            $lead->saveQuietly();
            $this->updateLeadProperties($lead);
            $odoo->addNoteTo('crm.lead', $lead->odoo_lead_id, sprintf("Leads link: <a target='_blank' href='%s'>%s</a>", route('voyager.leads.edit', $lead->id), route('voyager.leads.edit', $lead->id)));
        });

and the Odoo service class:

<?php

namespace App\Services\Odoo;

use App\Services\Odoo\Dto\PartnerDto;
use App\User;
use Obuchmann\OdooJsonRpc\Odoo as OdooRpc;

class Odoo
{
    public $rpc;

    public function __construct()
    {
        $this->rpc = app(OdooRpc::class);
    }

    public function getContactByEmail($email)
    {
        return $this->rpc->model('res.partner')
            ->where('email', '=', $email)
            ->first();
    }

    public function createOrUpdateContact(User $user)
    {
        if ($user->odoo_partner_id) {
            $this->updateContact($user);
        } else {
            $odooPartner = $this->getContactByEmail($user->email);
            if (!$odooPartner) {
                $partner_id = $this->createContact($user);
            } else {
                $partner_id = $odooPartner->id;
            }
            $user->odoo_partner_id = $partner_id;
            $user->save();
        }
    }

    public function addNoteTo($model, $modelId, $note)
    {
        return $this->rpc->model('mail.message')->create(
            [
                'body' => $note,
                'message_type' => 'comment',
                'model' => $model,
                'res_id' => $modelId,
                'subtype_id' => 2,
            ]
        );
    }

    protected function createContact(User $user)
    {
        return $this->rpc->model('res.partner')->create(PartnerDto::fromUser($user));
    }

    protected function updateContact(User $user)
    {
        return $this->rpc->updateById('res.partner', $user->odoo_partner_id, PartnerDto::fromUser($user));
    }
}

Nothing fancy.

Thanks

SwiTool avatar Jul 15 '25 06:07 SwiTool

Please update to v1.9.0 it introduces optimizations for usage in the cli/queue-worker

obuchmann avatar Jul 29 '25 19:07 obuchmann

Thank you, I will notice if the issue reproduces

SwiTool avatar Jul 29 '25 19:07 SwiTool