Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgKcy-0007ry-0C for pgsql-jdbc@arkaria.postgresql.org; Sun, 26 Mar 2023 07:17:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pgKcv-0004Lb-Tv for pgsql-jdbc@arkaria.postgresql.org; Sun, 26 Mar 2023 07:17:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgKcv-0004LS-Ka for pgsql-jdbc@lists.postgresql.org; Sun, 26 Mar 2023 07:17:17 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pgKcr-0003Mo-EU for pgsql-jdbc@lists.postgresql.org; Sun, 26 Mar 2023 07:17:17 +0000 Received: by mail-oi1-x230.google.com with SMTP id bj20so4231199oib.3 for ; Sun, 26 Mar 2023 00:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679815031; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=bdjqi/RIlX6hOMRT5RY8IspseQLAyoPghB40LCoyEio=; b=poHLvrjgJILcKSvQO+RekR4KwV+P/rlCOuVQ5SNN9EtX06THPkPS4RDbLe8AWbD3OI uyj22WVky+jNFQp/cq+b0uAUVPp7DCWeCWhk5OTNhDARxvv5gqNM6rBZE/x8gEzg+RUA O7Z1t8ztnLKPKAsBtPxmfkL9hrReCpKHCZv+Nx6mX2QDGh45q/Hg5p+aLtlaEUDQ6XEK 2B9h+4MkILwVcUIxuF6m68DQnAaZkmsFbAHk8P+rUd+YHXH4ZX9tnwbg/Wzt4GKrmzsL 3X2rceMaeCRGylxD7ckmWldgGOM5Aeg0CvakPOSOB7SYcZKWraBhbVfnOSaHXh0FWf/s lgqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679815031; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bdjqi/RIlX6hOMRT5RY8IspseQLAyoPghB40LCoyEio=; b=314/OVFiI02pgh34H0CS//b9Nz1oDtYLG7UnwGWH9sx5UcmBNNDC0MdOU4jG8uDxbn aJ4CxcWvM2HJlAayLHBurl72I/u/9Q2YFYWAyygyBXBB3ujq6iQqcuBfuFwLTQnBEgy0 MediVwBoJ3wykR1pyBdiAKxj24QO1/lVneKLXuHFPlpdUHbVH7JGHkzQX8GA5peh7qOT urW2d/P8Dy7Q+yZnNrshqyaX7eceQOqr1LxeSqkcG2tIRZoRJUJm+aez4l6hfsGIixnk LgkEw0NuQcCJStgdStUusNj7MWxMKpvzi1fsIvwRbeWwySZqgOfQLR/h0xI5Wifx9vHm bMVA== X-Gm-Message-State: AO0yUKVdgjCpzop4adAKSEC8cxGtL7KqZZblrfdw5/ozUKQhrbkKxaif u2YxXk/u6eHBTXSncnjmEutqa+4d3OuK0pmfVTHE41p3amPsRw== X-Google-Smtp-Source: AK7set9xb+6fVnq52KkDmRt7CR5WLnt5OqSp+4v1ELKPmtuoI2AEe5E1wrwYj3FeDjmcqcAVs/WRJTh2A4hIY4r2zEU= X-Received: by 2002:a05:6808:a04:b0:36e:f6f7:bb1a with SMTP id n4-20020a0568080a0400b0036ef6f7bb1amr2094243oij.5.1679815031258; Sun, 26 Mar 2023 00:17:11 -0700 (PDT) MIME-Version: 1.0 From: Andy Fan Date: Sun, 26 Mar 2023 15:16:59 +0800 Message-ID: Subject: Duplicate Proxy.newProxyInstance calls during PGXAConnection.getConnection? To: pgsql-jdbc@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000003a017105f7c86aab" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003a017105f7c86aab Content-Type: text/plain; charset="UTF-8" In the PGXAConnection.GetConnection() [1], we can see the below code: @Override public Connection getConnection() throws SQLException { // *the first time ConnectionHandler has been created.* Connection conn = super.getConnection(); // When we're outside an XA transaction, autocommit // is supposed to be true, per usual JDBC convention. // When an XA transaction is in progress, it should be // false. if (state == State.IDLE) { conn.setAutoCommit(true); } /* * Wrap the connection in a proxy to forbid application from fiddling with transaction state * directly during an XA transaction */ // *ConnectionHandler is created again here. * ConnectionHandler handler = new ConnectionHandler(conn); return (Connection) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler); } However I think the proxy has already been created at the first line: super.getConnection(), and then it is created later. Is it a duplication? [1] https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java#L86 -- Best Regards Andy Fan --0000000000003a017105f7c86aab Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In the PGXAConnection.GetConnection() [1], we can see the = below code:

However I think the proxy has already been created at the fir= st line: super.getConnection(),=C2=A0
and then it is created late= r.=C2=A0 Is it a duplication?=C2=A0

--0000000000003a017105f7c86aab--
  @Override
  public Connection getConnection() throws SQLException {
    // the first time Connect=
ionHandler has been created.
    Connection conn =3D super.getConnection();  =20

    // When we're outside an XA transaction, autocommit
    // is supposed to be true, per usual JDBC convention.
    // When an XA transaction is in progress, it should be
    // false.
    if (state =3D=3D State.IDLE) {
      conn.setAutoCommit(true);
    }

    /*
     * Wrap the connection in a proxy to forbid application from fiddling w=
ith transaction state
     * directly during an XA transaction
     */
    // ConnectionHandler is created again here. 
    ConnectionHandler handler =3D new ConnectionHandler(conn);
    return (Connection) Proxy.newProxyInstance(getClass().getClassLoader(),
        new Class[]{Connection.class, PGConnection.class}, handler);
  }