Skip to content

Oracle AQ consumers fail to read new message after having no messages for a long time #450

Open
@mkmoisen

Description

@mkmoisen

I have a consumer thread listening to an Oracle AQ queue in dequeue wait forever mode.

Everything works great, except for when there has been no message in the queue for an hour or so.

After adding a message to the queue, the dequeue never happens.

I know the thread is still alive and apparently attempting to dequeue, because I can see it in gv$session with the event Streams AQ: waiting for messages in the queue, and the previous sql id is pointing to a query that hits the AQ$_queuename_F table. (If I kill the app, this session is terminated).

I know there is a message in the queue, and that it has never been dequeued, which I can tell from querying the queue table.

Killing the application and restarting it results in the message being immediately dequeued, so I know there is no filter dequeue condition for example stopping it.

I was under the impression that if there was some kind of network disconnect, then Oracle would detect this, and the session would be terminated, and not be visible in gv$session.


Would anyone happen to have any ideas on what could possibly be causing this behavior or how I could debug it?

The reason I think it may be a bug is because gv$session is still populated with this thread with the event Streams AQ: waiting for messages in the queue

I have been reliably seeing this behavior.


I am doing simple, single consumer queues with everything pretty standard:

CREATE OR REPLACE NONEDITIONABLE TYPE MYQUEUE_TYPE AS OBJECT (
    foo VARCHAR2(128),
    bar VARCHAR2(128)
);

BEGIN
    DBMS_AQADM.CREATE_QUEUE_TABLE(
        queue_table => 'MYQUEUE',
        queue_payload_type => 'MYQUEUE_TYPE'
    );

    DBMS_AQADM.CREATE_QUEUE(
        queue_name => 'MYQUEUE',
        queue_table => 'MYQUEUE'
    );

    DBMS_AQADM.START_QUEUE(
        queue_name => 'MYQUEUE'
    );
END;
/
while True:
    try:
        conn = oracledb.connect(...)
     
        myqueue_type = conn.gettype('MYSCHEMA.MYQUEUE_TYPE')
     
        queue = conn.queue('MYSCHEMA.MYQUEUE', myqueue_type)

        cur = conn.cursor()
        result = cur.execute(
            '''
                select inst_id, sid, serial#
                from gv$session 
                where 1=1
                    and audsid = userenv('SESSIONID') 
                    and inst_id = userenv('INSTANCE') 
                    and sid = userenv('SID')
            '''
        )
        print(result)
        
        print('attempting dequeue')
        
        entry = queue.dequeue()
        
        print('dequeued')

        ...
     
        conn.commit()
    except Exception as ex:
        conn.rollback()
  1. What versions are you using?

Oracle 19

>>> import sys
>>> import platform
>>>
>>> print("platform.platform:", platform.platform())
platform.platform: Windows-11-10.0.22631-SP0
>>> print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
sys.maxsize > 2**32: True
>>> print("platform.python_version:", platform.python_version())
platform.python_version: 3.13.0

>>> import oracledb
>>> print("oracledb.__version__:", oracledb.__version__)
oracledb.__version__: 2.5.1
  1. Is it an error or a hang or a crash?

Hang

  1. What error(s) or behavior you are seeing?

Thread that is dequeing from the queue hangs forever and does not read new messages in the queue.

  1. Does your application call init_oracle_client()?

Yes, thick mode.

  1. Include a runnable Python script that shows the problem.

Cannot be reproduced without waiting for several hours after the last message.

import oracledb

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions