[19.0] queue_job: Jobs stay pending after the jobrunner's database connection is silently dropped

Aberta
#984 1 comentário 1 reação 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@HoloborodkoBohdan já está trabalhando nisso.

Desde 28/9/2026.

  • #1000 de @HoloborodkoBohdan — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
postgresql, python
Domínio
backend

Direção de pesquisa

The issue points to queue_job/jobrunner/runner.py, specifically _connection_info_for() and QueueJobRunner.run(). Review how connection parameters are assembled and how the runner handles a lost connection; the issue proposes enabling TCP keepalives with defaults. An open linked pull request already addresses this issue, so check that work before making changes.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug

Module

  • queue_job

Describe the bug

The jobrunner keeps one database connection open for as long as it runs, and it holds
the master lock on that connection.

If that connection dies without the server telling the client (a network problem, or a
database failover), two things happen:

  • PostgreSQL drops the lock, because the session is gone.
  • The runner does not notice. Its socket still looks open, so it just waits forever.

From then on no jobs are dispatched at all. Nothing is logged. The process looks healthy.
Only restarting Odoo fixes it.

The runner already has code to reconnect if the database connection breaks (the
except Exception block in run()), but it never runs, because nothing raises an error.
The runner is simply stuck waiting.

To Reproduce

Affected versions: 19.0

Steps to reproduce the behavior:

  1. Start Odoo with queue_job in server_wide_modules (odoo.conf). Check the runner has the lock:
    SELECT count(*) FROM pg_locks WHERE locktype = 'advisory'; should return 1.
  2. Break the connection silently, so the client is never told. For example, add a firewall
    rule that drops traffic between Odoo and PostgreSQL. (Using pg_terminate_backend will
    not work, because that tells the client.)
  3. Add a job. It stays pending forever. The lock count is now 0, and nothing appears in
    the log.

Expected behavior
The runner should notice the connection is dead and reconnect, which is what the
except Exception block is already there to do.

zooming in to the except Exception mentioned:
QueueJobRunner.run() in queue_job/jobrunner/runner.py.
The outer loop wraps initialize_databases() and the processing loop in a try/except,
and the last of its four handlers is:

except Exception:
    _logger.exception("exception: sleeping %ds and retrying", ERROR_RECOVERY_DELAY)
    self.close_databases()
    time.sleep(ERROR_RECOVERY_DELAY)

Additional context

  • Running Odoo in AWS ECS and Aurora PostgreSQL.
  • Odoo WEB service and CRON service separated
  • Both web and cron service has server_wide_modules = queue_job
  • cron service has http_enable = False and runs on a different port

Proposed Fix:
In queue_job/jobrunner/runner.py, at the end of
_connection_info_for(), just before the return:

# added
connection_info.setdefault("keepalives", 1)
connection_info.setdefault("keepalives_idle", 60)
connection_info.setdefault("keepalives_interval", 10)
connection_info.setdefault("keepalives_count", 5)

The fix is to turn on TCP keepalives there, so a dead connection is noticed after about a
minute instead of never.

Linguagem predominante
Python
Estrelas
271
Forks
602
Merge médio
4d 4h
PRs com merge (30d)
6

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de OCA/queue

Todas as issues de OCA/queue

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.