Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jD9PS-000572-JB for psycopg@arkaria.postgresql.org; Sat, 14 Mar 2020 16:13:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jD9PR-0002OH-6L for psycopg@arkaria.postgresql.org; Sat, 14 Mar 2020 16:13:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jD9PQ-0002OA-QS; Sat, 14 Mar 2020 16:13:08 +0000 Received: from mout.gmx.net ([212.227.17.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jD9PN-0004r6-Pw; Sat, 14 Mar 2020 16:13:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584202383; bh=LRBG0grSKCNjKWYUvqXj5GpsdnoG4qOWnnFjN/pw5eU=; h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To; b=IEqtmreBSIJTtdWc49RfBst1wdK/IZkWe32bB2PJViQMTSTEVUuLUX2UzdHhoWIzc 0BGAgeH/CAw1qHsGEn7u5gMW79AaMaDMZoZzY5jCGdWKiUVi74WtuOvqGTrdZui3xN zxWOJb/siFifTaxUrKlcKYDBHWt+G9+DY3Gf4Udo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from hermes ([77.13.192.245]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M5QFB-1jBmUl3dQr-001NJc; Sat, 14 Mar 2020 17:13:02 +0100 Received: from ncq by hermes with local (Exim 4.92) (envelope-from ) id 1jD9PH-0006R1-Us; Sat, 14 Mar 2020 17:13:00 +0100 Date: Sat, 14 Mar 2020 17:12:59 +0100 From: Karsten Hilbert To: psycopg@lists.postgresql.org, psycopg@postgresql.org Subject: Re: wire protocol errors on Debian (py3/psyco 2.8) Message-ID: <20200314161259.GD1104@hermes.hilbert.loc> Mail-Followup-To: psycopg@lists.postgresql.org, psycopg@postgresql.org References: <20200314153421.GC1104@hermes.hilbert.loc> <1e6ef8fb-1efd-ab1b-7dae-a880b5d53ee0@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1e6ef8fb-1efd-ab1b-7dae-a880b5d53ee0@aklaver.com> Ma_X_il-Followup-to: d Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net X-Pri_X_ority: 2 (High) User-Agent: Mutt/1.10.1 (2018-07-13) Sender: X-Provags-ID: V03:K1:loqu/3DER+TQZ8YKHdLXvKlNWwEcaIg9yy3tfcilZSzxDHt7Me3 GL4Ghluh1jVxVoclJbLtcMFsf28FmXCZXdI7z3E/j53Wun0SGuCQE90m+OecEilfLhmjRkY QnXgaPCjoemaKFRwSA2AR7bLPJzkjpY6y5rBeMeNCh39xUiHdNJ0bfrAAqzkc6oQVBkoVX3 5auj1don9uzj3JB9nxEVw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:UYN4499RSXc=:1yI4D4G1eBdbMdJSSSvDjg O+nUX7nKasc89tkwUgX3irVs3RB5h6vz7rp0Tl2XyDsbhBdk5nO8LpK0GaVNxeicW+oREnSCt SERtxXK/9VGDmvkcczeELVC1RpY0RyjVQCx1+KyI4Lk+Up/nlHgm809FDkxHOz2XmPSgiLh96 r3iib94h/3lHY2coWvE7l42t9PEuLzPOeSylLoRn7E8scJG4aC3i5EgzXDB7VPgWIciyZWFSH dYe6KwEULyl+ZczOA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Post: List-Owner: List-Archive: Precedence: bulk Dear Adrian, unfortunately, we don't have direct contact with the reporter (only via our mailing list and they haven't answered so far). > How was psycopg2 installed? Given they are running a "standard" Debian/Unstable with a Debian package of GNUmed installed and the matching psycopg2 package version psycopg2 module version: 2.8.4 (dt dec pq3 ext lo64) I suspect they apt-get install'ed it. Which assumption seems supported by the package file string in: PostgreSQL via DB-API module "": API level 2.0, thread safety 2, para= meter style "pyformat" The one thing that's odd is that the Python version Python 3.7.6 (default, Jan 19 2020, 22:34:52) <\n>[GCC 9.2.1 20200117] on= linux (posix) does not match what's available from Debian: python3: Installiert: 3.7.3-1 Installationskandidat: 3.7.3-1 Versionstabelle: 3.8.2-1 500 500 https://deb.debian.org/debian unstable/main i386 Packages 3.7.5-3 500 500 https://deb.debian.org/debian bullseye/main i386 Packages *** 3.7.3-1 990 990 https://deb.debian.org/debian buster/main i386 Packages 100 /var/lib/dpkg/status > What is the code being run when the errors are thrown? It happens (two reports so far) at different stages during the bringup phase of the GNUmed client. The code being run is the same, but the time of occurrence is different. case 1: select vco.value from cfg.v_cfg_opts_numeric vco where vco.owner =3D CURR= ENT_USER and vco.workplace =3D %(wp)s and vco.option =3D %(opt)s and vco.c= ookie is null limit 1 case 2: select _(message) from cfg.db_logon_banner where _() translates "message". This is the Python code being run (the place of error marked with xxxxx): def run_ro_queries(link_obj=3DNone, queries=3DNone, verbose=3DFalse, retur= n_data=3DTrue, get_col_idx=3DFalse): """Run read-only queries. must be a list of dicts: [ {'cmd': , 'args': or }, {...}, ... ] """ if isinstance(link_obj, dbapi._psycopg.cursor): curs =3D link_obj curs_close =3D lambda *x:None tx_rollback =3D lambda *x:None readonly_rollback_just_in_case =3D lambda *x:None elif isinstance(link_obj, dbapi._psycopg.connection): curs =3D link_obj.cursor() curs_close =3D curs.close tx_rollback =3D link_obj.rollback if link_obj.autocommit is True: # readonly connection ? readonly_rollback_just_in_case =3D link_obj.rollback else: # do not rollback readonly queries on passed-in readwrite # connections just in case because they may have already # seen fully legitimate write action which would get lost readonly_rollback_just_in_case =3D lambda *x:None elif link_obj is None: conn =3D get_connection(readonly =3D True, verbose =3D verbose) curs =3D conn.cursor() curs_close =3D curs.close tx_rollback =3D conn.rollback readonly_rollback_just_in_case =3D conn.rollback else: raise ValueError('link_obj must be cursor, connection or None but not [%= s]' % link_obj) if verbose: _log.debug('cursor: %s', curs) for query in queries: try: args =3D query['args'] except KeyError: args =3D None try: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx curs.execute(query['cmd'], args) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if verbose: gmConnectionPool.log_cursor_state(curs) except PG_ERROR_EXCEPTION as pg_exc: _log.error('query failed in RO connection') gmConnectionPool.log_pg_exception_details(pg_exc) try: curs_close() except PG_ERROR_EXCEPTION as pg_exc2: _log.exception('cannot close cursor') gmConnectionPool.log_pg_exception_details(pg_exc2) try: tx_rollback() # need to rollback so ABORT state isn't preserved in po= oled conns except PG_ERROR_EXCEPTION as pg_exc2: _log.exception('cannot rollback transaction') gmConnectionPool.log_pg_exception_details(pg_exc2) if pg_exc.pgcode =3D=3D sql_error_codes.INSUFFICIENT_PRIVILEGE: details =3D 'Query: [%s]' % curs.query.strip().strip('\n').strip().str= ip('\n') if curs.statusmessage !=3D '': details =3D 'Status: %s\n%s' % ( curs.statusmessage.strip().strip('\n').strip().strip('\n'), details ) if pg_exc.pgerror is None: msg =3D '[%s]' % pg_exc.pgcode else: msg =3D '[%s]: %s' % (pg_exc.pgcode, pg_exc.pgerror) raise gmExceptions.AccessDenied ( msg, source =3D 'PostgreSQL', code =3D pg_exc.pgcode, details =3D details ) raise except Exception: _log.exception('error during query run in RO connection') gmConnectionPool.log_cursor_state(curs) try: curs_close() except PG_ERROR_EXCEPTION as pg_exc: _log.exception('cannot close cursor') gmConnectionPool.log_pg_exception_details(pg_exc) try: tx_rollback() # need to rollback so ABORT state isn't preserved in po= oled conns except PG_ERROR_EXCEPTION as pg_exc: _log.exception('cannot rollback transation') gmConnectionPool.log_pg_exception_details(pg_exc) raise data =3D None col_idx =3D None if return_data: data =3D curs.fetchall() if verbose: _log.debug('last query returned [%s (%s)] rows', curs.rowcount, len(dat= a)) _log.debug('cursor description: %s', curs.description) if get_col_idx: col_idx =3D get_col_indices(curs) curs_close() # so we can see data committed meanwhile if the # link object had been passed in and thusly might # be part of a long-running read-only transaction readonly_rollback_just_in_case() return (data, col_idx) Thanks, Karsten =2D- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B