Skip to content
New issue

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

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

Already on GitHub? # to your account

Debugger hangs when stepping into nested function/procedure and RuntimeError(f'{self!r} is bound to a different event loop') raised #8443

Open
ssenior45 opened this issue Feb 12, 2025 · 0 comments

Comments

@ssenior45
Copy link

Describe the bug

Using the debugger to step into code.

When using the debugger and stepping into a nested function or procedure the UI hangs.

Enabling logging on pgAdmin reveals an error message in the logs.

To Reproduce

Steps to reproduce the behavior:

  1. Create Postgres 15 server with plugin_debugger/pldbgapi extension installed

  2. Create test schema and functions

drop schema testdebug cascade;

create schema testdebug;

create or replace function testdebug.testfunc(IN p1 character varying, IN p2 numeric, IN p3 character varying, IN p4 numeric)
    returns void
    language plpgsql
as
$$
  declare
    i   integer := 0;
    s   varchar(3);
  begin
   RAISE NOTICE 'START';
   i := 2;
   s := 'asd';
   RAISE NOTICE 'i = %', i;
   RAISE NOTICE 's = %', s;
   RAISE NOTICE 'p1 = %', p1;
   RAISE NOTICE 'p2 = %', p2;
   RAISE NOTICE 'p3 = %', p3;
   RAISE NOTICE 'p4 = %', p4;
   RAISE NOTICE 'END';
end;
$$;

create or replace function testdebug.testfunc(IN p1 character varying, IN p2 numeric, IN p3 character varying DEFAULT NULL::character varying)
    returns void
    language plpgsql
as
$$
  declare
    p_1     numeric := 999;
  begin
    perform testdebug.testfunc( p1, p2, p3, p_1 );
end;
$$;
  1. Enable pgAdmin logging

Instructions for MacOS

cat > /Applications/pgAdmin\ 4.app/Contents/Resources/web/config_local.py <<EOF
import logging

# Application log level - one of:
#   CRITICAL 50
#   ERROR    40
#   WARNING  30
#   SQL      25
#   INFO     20
#   DEBUG    10
#   NOTSET    0
CONSOLE_LOG_LEVEL = logging.DEBUG
FILE_LOG_LEVEL = logging.DEBUG

# Log format.
CONSOLE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s'
FILE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s'

# Log file name
LOG_FILE = '/tmp/pgadmin4_debug.log'
EOF
  1. Find the testdebug.testfunc(IN p1 character varying, IN p2 numeric, IN p3 character varying DEFAULT NULL::character varying) function in the schema tree
  2. Right click -> Debugging -> Debug
  3. Enter parameter values -> Debug
  4. Click Step Into
  5. In the new function Click Step Into
  6. UI now "hangs" - all debugging buttons are greyed out

Expected behavior

The debugger should not hang, we should be able to step into the nested function as we can with the parent function

Error message

Full pgAdmin logs attached but relevant errors are

2025-02-11 20:36:24,368: SQL	pgadmin:	Status message for (Query-id: 3293912)
2025-02-11 20:36:24,368: SQL	pgadmin:	Polling result for (Query-id: 3293912)
2025-02-11 20:36:24,369: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:24] "GET /debugger/poll_end_execution_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:24,506: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:24] "GET /debugger/execute_query/5239296/step_into HTTP/1.1" 200 -
2025-02-11 20:36:24,630: SQL	pgadmin:	Status message for (Query-id: 3293912)
2025-02-11 20:36:24,630: SQL	pgadmin:	Polling result for (Query-id: 3293912)
2025-02-11 20:36:24,632: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:24] "GET /debugger/poll_end_execution_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:24,720: SQL	pgadmin:	Polling result for (Query-id: 7086391)
2025-02-11 20:36:24,721: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:24] "GET /debugger/poll_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:24,737: SQL	pgadmin:	Execute (void) by pgadmin4@pgadmin.org on postgres@localhost/test #12 - CONN:9001867 (Query-id: 2378430):
SET search_path="$user", public,public;
2025-02-11 20:36:24,753: SQL	pgadmin:	Execute (void) by pgadmin4@pgadmin.org on postgres@localhost/test #12 - CONN:9001867 (Query-id: 1656886):
SET search_path="$user", public,public;
2025-02-11 20:36:24,790: SQL	pgadmin:	Execute (dict) by pgadmin4@pgadmin.org on postgres@localhost/test #12 - CONN:9001867 (Query-id: 7311054):
SELECT * FROM pldbg_get_breakpoints(1::int)

2025-02-11 20:36:24,790: ERROR	pgadmin:	<asyncio.locks.Lock object at 0x10fc218e0 [unlocked, waiters:1]> is bound to a different event loop
Traceback (most recent call last):
  File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/driver/psycopg3/cursor.py", line 281, in execute
    return asyncio.run(self._execute(query, params))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/driver/psycopg3/cursor.py", line 292, in _execute
    return await _async_cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/psycopg/cursor_async.py", line 92, in execute
    async with self._conn.lock:
               ^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/locks.py", line 14, in __aenter__
    await self.acquire()
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/locks.py", line 105, in acquire
    fut = self._get_loop().create_future()
          ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/mixins.py", line 20, in _get_loop
    raise RuntimeError(f'{self!r} is bound to a different event loop')
RuntimeError: <asyncio.locks.Lock object at 0x10fc218e0 [unlocked, waiters:1]> is bound to a different event loop
2025-02-11 20:36:24,794: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:24] "GET /debugger/execute_query/5239296/get_breakpoints HTTP/1.1" 200 -
2025-02-11 20:36:24,888: SQL	pgadmin:	Status message for (Query-id: 3293912)
2025-02-11 20:36:24,888: SQL	pgadmin:	Polling result for (Query-id: 3293912)
2025-02-11 20:36:24,889: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:24] "GET /debugger/poll_end_execution_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:25,147: SQL	pgadmin:	Status message for (Query-id: 3293912)
2025-02-11 20:36:25,147: SQL	pgadmin:	Polling result for (Query-id: 3293912)
2025-02-11 20:36:25,148: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:25] "GET /debugger/poll_end_execution_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:25,408: SQL	pgadmin:	Status message for (Query-id: 3293912)
2025-02-11 20:36:25,408: SQL	pgadmin:	Polling result for (Query-id: 3293912)
2025-02-11 20:36:25,409: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:25] "GET /debugger/poll_end_execution_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:25,669: SQL	pgadmin:	Status message for (Query-id: 3293912)
2025-02-11 20:36:25,669: SQL	pgadmin:	Polling result for (Query-id: 3293912)
2025-02-11 20:36:25,670: INFO	werkzeug:	127.0.0.1 - - [11/Feb/2025 20:36:25] "GET /debugger/poll_end_execution_result/5239296/ HTTP/1.1" 200 -
2025-02-11 20:36:25,763: SQL	pgadmin:	Execute (void) by pgadmin4@pgadmin.org on postgres@localhost/test #12 - CONN:9001867 (Query-id: 4499284):
SET search_path="$user", public,public;
2025-02-11 20:36:25,764: ERROR	pgadmin:	<asyncio.locks.Lock object at 0x10fc218e0 [unlocked, waiters:1]> is bound to a different event loop
Traceback (most recent call last):
  File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/driver/psycopg3/cursor.py", line 281, in execute
    return asyncio.run(self._execute(query, params))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/driver/psycopg3/cursor.py", line 292, in _execute
    return await _async_cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/psycopg/cursor_async.py", line 92, in execute
    async with self._conn.lock:
               ^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/locks.py", line 14, in __aenter__
    await self.acquire()
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/locks.py", line 105, in acquire
    fut = self._get_loop().create_future()
          ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/mixins.py", line 20, in _get_loop
    raise RuntimeError(f'{self!r} is bound to a different event loop')
RuntimeError: <asyncio.locks.Lock object at 0x10fc218e0 [unlocked, waiters:1]> is bound to a different event loop
2025-02-11 20:36:25,765: SQL	pgadmin:	Execute (async) by pgadmin4@pgadmin.org on postgres@localhost/test #12 - CONN:9001867 (Query-id: 3144023):
SELECT
    p.func, p.targetName, p.linenumber,
    pldbg_get_source(1::INTEGER, p.func) AS src,
    (SELECT
        s.args
     FROM pldbg_get_stack(1::INTEGER) s
     WHERE s.func = p.func ORDER BY s.level LIMIT 1) AS args
FROM pldbg_step_into(1::INTEGER) p

2025-02-11 20:36:25,766: ERROR	pgadmin:	<asyncio.locks.Lock object at 0x10fc218e0 [unlocked, waiters:1]> is bound to a different event loop
Traceback (most recent call last):
  File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/driver/psycopg3/cursor.py", line 281, in execute
    return asyncio.run(self._execute(query, params))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/driver/psycopg3/cursor.py", line 292, in _execute
    return await _async_cursor.execute(self, query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/psycopg/cursor_async.py", line 92, in execute
    async with self._conn.lock:
               ^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/locks.py", line 14, in __aenter__
    await self.acquire()
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/locks.py", line 105, in acquire
    fut = self._get_loop().create_future()
          ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/mixins.py", line 20, in _get_loop
    raise RuntimeError(f'{self!r} is bound to a different event loop')
RuntimeError: <asyncio.locks.Lock object at 0x10fc218e0 [unlocked, waiters:1]> is bound to a different event loop

Desktop (please complete the following information):

  • OS: OSX 14.7.3
  • Version: Reproduces on pgAdmin 8.1.2 and 9.0
  • Mode: Desktop
  • Browser (if running in server mode): N/A
  • Package type: DMG

pgadmin4_v90_debug_stacktrace.log
pgadmin4_v812_debug_stacktrace.log

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants