这是indexloc提供的服务,不要输入任何密码
Skip to content

Query Tool: stuck in query execution (race condition w/ background auto-completion query on slow connections?); after cancelling the stuck query, Query Tool tab is unusable. #6356

@vladr

Description

@vladr

Describe the bug

Two related issues seem to be occurring in sequence:

A) If starting query execution (▸ button) while the editor's auto-complete drop-down is still being populated, the query seems to start executing but remains stuck at "Waiting for the query to complete...";

No error or exception is logged.

B) After cancelling the seemingly stuck query (■ button), trying to execute that or any other query in the same Query Tool tab (including an invalid query) pretends to succeed ("Query returned successfully in xx msec." under "Messages") but the "Data Output" is never updated.

The following is logged:

2023-06-02 13:02:39,615: ERROR  pgadmin:        <asyncio.locks.Lock object at 0x11948dfd0 [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.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.11/lib/python3.11/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.11/lib/python3.11/asyncio/base_events.py", line 653, 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.11/lib/python3.11/site-packages/psycopg/cursor_async.py", line 89, in execute
    async with self._conn.lock:
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/locks.py", line 15, in __aenter__
    await self.acquire()
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/locks.py", line 106, in acquire
    fut = self._get_loop().create_future()
          ^^^^^^^^^^^^^^^^
  File "/Applications/pgAdmin 4.app/Contents/Frameworks/Python.framework/Versions/3.11/lib/python3.11/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 0x11948dfd0 [unlocked, waiters:1]> is bound to a different event loop

To Reproduce

Steps to reproduce the behavior:

  1. Issue A
  2. Open a new Query Tool tab, or go to an existing Query Tool tab where a previous query was successfully executed;
  3. Write/paste in a valid query, but do not execute yet;
  4. Start editing the field names after "SELECT" as to trigger the auto-completion drop-down;
  5. While the auto-completion suggestions are still loading (drop-down reads "Loading..."), hit the ▸ button to execute the query;
    N.B. this step is timing-sensitive and may be best reproduced using a non-local (slow-ish) PG connection;
  6. --> Observe the "Data Output" tab stuck in "Waiting for the query to complete..." mode
  7. Issue B
  8. Cancel the query from step 5 above (■ button);
  9. In the same Query Tool tab, re-execute the query from step 5 (▸ button), or any other query, including an invalid query (which should normally come back with an error from the server);
  10. --> Observe the "Messages" tab getting the focus, reading "Query returned successfully" (even for a clearly invalid query);
  11. --> Observe the "Data Output" tab containing whatever it contained prior to step 7 before;
  12. --> Observe an error being logged to ~/.pgadmin/pgadmin4.log

Workaround: disable "Autocomplete on key press" in the Query Tool options.

Expected behavior

  • no stuck query in step 6 above;
  • no buggy behavior in steps 10-11 and no error in step 12 above.

Error message

If possible, include the full, unedited text of any error messages displayed.

Screenshots

n/a

Desktop (please complete the following information):

  • OS: macOS-12.6.4-x86_64-i386-64bit
  • Version: 7.2
  • Mode: Desktop
  • Browser (if running in server mode): n/a
  • Package type: DMG

Additional context

n/a

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions