pgadmin-org / pgadmin4

pgAdmin is the most popular and feature rich Open Source administration and development platform for PostgreSQL, the most advanced Open Source database in the world.
https://www.pgadmin.org
Other
2.45k stars 643 forks source link

debian 11 (bullseye) pgadmin4-server package: ImportError: PyO3 modules may only be initialized once per interpreter process #6718

Closed olivluca closed 1 year ago

olivluca commented 1 year ago

Versions 7.5 and 7.6 of the pgadmin4-server package for debian 11 don't work. The traceback in the log is

Traceback (most recent call last):
  File "./pgAdmin4.py", line 43, in <module>
    from eventlet import hubs
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/__init__.py", line 17, in <module>
    from eventlet import convenience
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/green/socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/support/greendns.py", line 79, in <module>
    setattr(dns, pkg, import_patched('dns.' + pkg))
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/support/greendns.py", line 61, in import_patched
    return patcher.import_patched(module_name, **modules)
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/patcher.py", line 132, in import_patched
    return inject(
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/eventlet/patcher.py", line 109, in inject
    module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/dns/dnssecalgs/__init__.py", line 5, in <module>
    from dns.dnssecalgs.dsa import PrivateDSA, PrivateDSANSEC3SHA1
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/dns/dnssecalgs/dsa.py", line 4, in <module>
    from cryptography.hazmat.primitives import hashes
  File "/usr/pgadmin4/venv/lib/python3.9/site-packages/cryptography/hazmat/primitives/hashes.py", line 10, in <module>
    from cryptography.hazmat.bindings._rust import openssl as rust_openssl
ImportError: PyO3 modules may only be initialized once per interpreter process

Version 7.4 of the package works.

$ LC_ALL=C apt-cache policy pgadmin4-server
pgadmin4-server:
  Installed: 7.4
  Candidate: 7.6
  Version table:
     7.6 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
     7.5 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
 *** 7.4 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
        100 /var/lib/dpkg/status
     7.3 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
     7.2 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
     7.1 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
     7.0 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
     6.21 500
        500 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4/main amd64 Packages
nikhil-mohite commented 1 year ago

@FaharAbbasRizvi , Can you please verify it once?

olivluca commented 1 year ago

In case it's relevant (it probably is) it's the only package I installed (neither pgadmin4 nor pgadmin4-desktop) and I'm running under uwsgi with this ini file:

[uwsgi]
processes = 1
threads = 25
chdir = /usr/pgadmin4/web/
wsgi-file = /usr/pgadmin4/web/pgAdmin4.wsgi
uid = pgadmin4
plugins = python3
mount=/pgadmin=pgAdmin4:app
virtualenv=/usr/pgadmin4/venv
manage-script-name = true

(the wsgi-file is the one provided by the package)

FaharAbbasRizvi commented 1 year ago

I am not able to reproduce the issue on Debian 11

Screen Shot 2023-08-28 at 5 20 52 PM

Could you please share the exact step to reproduce?

FlossyWeb commented 1 year ago

I've got the same issue here, everything's fine using pgadmin4-server apt package version 7.4 on Bebian 11 with python 3.9.2. But when I upgrade to pgadmin4-server 7.6, my uWSGI service pops up with the same error:

Capture d’écran 2023-08-31 à 16 25 05

My PgAdmin server runs through Systemd-uWSGI-Nginx.

olivluca commented 1 year ago

I am not able to reproduce the issue on Debian 11

Mhh, the mail I received from github said "I am able to reproduce the issue" so I disregarded it :cry:

Could you please share the exact step to reproduce?

I just installed the package pgadmin4-server, configured it to run under uwsgi (package uwsgi) with the configuration file posted above, then in one nginx server (package nginx-extras) I have this snippet

   location = /pgadmin4 {
     return 301 /pgadmin/;
   }

   location ^~ /pgadmin {
     include snippets/lemon.conf;
     include uwsgi_params;
     uwsgi_param REMOTE_USER $lmremote_user;
     uwsgi_pass unix:/run/uwsgi/app/pgadmin4/socket;
   }

snippets/lemon.conf is for the lemonldap authentication portal, however I also tested with an hardcoded user and no authentication

   location ^~ /pgadmin {
     include uwsgi_params;
     uwsgi_param REMOTE_USER luca;
     uwsgi_pass unix:/run/uwsgi/app/pgadmin4/socket;
   }

uwsgi_params is unmodified from the nginx-common package

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;
FlossyWeb commented 1 year ago

My Nginx configuration is different `upstream pgadmin { server unix:///run/pgadmin4/pgadmin4.sock; } [...]

location ^~ /pgadmin { include uwsgi_params; uwsgi_pass pgadmin; } ` Although I don't think it really matters regarding this issue, also I'm not a Python ninja so...

yogeshmahajan-1903 commented 1 year ago

Issue is due to cryptography version. Downgrading version to 40.0.2, issue is resolved.

yogeshmahajan-1903 commented 1 year ago

This can be fixed only after - https://github.com/pyca/cryptography/issues/9016. Issue is only reproducible if pgAdmin launched using uWSGI service/uwsgi module installed in venv.

olivluca commented 1 year ago

For the time being could you do the same as in this commit (mentioned in that bug report)? https://github.com/zigbeefordomoticz/Domoticz-Zigbee/commit/f8d16ff995207e162cf44812cb49e3b523182822

anilsahoo20 commented 1 year ago

Tested and verified on Snapshot build: https://www.postgresql.org/ftp/pgadmin/pgadmin4/snapshots/2023-09-29/ Environment: Debian 11(Bullseye) amd64->pgAdmin 4 Server mode

olivluca commented 1 year ago

Thank you for fixing it.

olivluca commented 8 months ago

The issue reappeared in debian 11 packages for versions 8.0, 8.1 and 8.2 :disappointed: Back to 7.8 (after manually correcting issue #6874)