Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRrRT-003PRY-Qz for pgsql-jdbc@arkaria.postgresql.org; Fri, 04 Aug 2023 09:49:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qRrRS-0065zn-Aj for pgsql-jdbc@arkaria.postgresql.org; Fri, 04 Aug 2023 09:49:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRrRS-0065zf-3k for pgsql-jdbc@lists.postgresql.org; Fri, 04 Aug 2023 09:49:54 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qRrRP-000WCi-UU for pgsql-jdbc@postgresql.org; Fri, 04 Aug 2023 09:49:53 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2b9fa64db41so30061641fa.1 for ; Fri, 04 Aug 2023 02:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691142591; x=1691747391; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=r8LJHdj2FybWbFIlFEhJkaRUw0VSBed0KxyAetjF7fM=; b=Y8hctNQ/Kls8SP9NKgcbqyGwSmoCd1fF0eyn3Czj6fznNi35K5H2juPUeaIr5Hsl02 bG96aN0R4xxBOC0ut4dKzH0kJpUihsCmPaXf91rBjcHXi3bsj874Kpnjcsg7l6l/Hmfm 2gUVZEo9oCk+Hrx1EyihBgfbpf79pYOTNyI9gvaQSHyg6Mew/K37GzWO7Iykp4aUaIW/ /vyv3KUSSxhcnF38+88lr+WQlnXkcLMRwaiKHWOlG/ej5r2qTajRzPj1PYSNtXYXzsQD sFIJpJzNgR/oNADqS9cy9TvGD12jU9MqDhlQf8yHzWocRKuh9Zlw7Yr1DuOEIlAR5AEf LCbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691142591; x=1691747391; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r8LJHdj2FybWbFIlFEhJkaRUw0VSBed0KxyAetjF7fM=; b=N+ypxDGPWvA55+L1NKVUx9SZHH3lv4fCm5p2C8pveFvYzHkeD6zs/0ZNAflW+LQ4wf HRaQKJuVu6Smi+UHV1pQVX8atsszsj+zY2zITD4zignE7wS8nFhYfXZTTF7rOnv+4lXB 8uH3fT6cEqGhK/afM0lC/yZqRyB/pKDxzssKE/D+Hbkt6uwgJhuuMEH6OTKAZwchFv6Y PDKqUNr2UKA7ZIIABzgvdatvJq83ytfBGdTmRqYtvlIGnHHyq5E9O8UXVynxT5oIsi/V Mb9y+FoH+2vKZGlFzcHNVMa3Rh2bI1D86O2hlqh3LUI5btQFKCEf/vX2IvUH+7u6D9WZ F7AQ== X-Gm-Message-State: AOJu0YzLsnCnNj6+avia47QtHtle0F5ihx0jCsWjQHVXP4ylfHXW2R6I i6l2nU7u54soh40fKPge4xHicZb233KuPPBDPtI7yqQ4 X-Google-Smtp-Source: AGHT+IGFyT+xTXwqpI91BaEaG/SGo1By0d+uWLpVUBZowRFkIiCcmh0vtJ/mqCgedK9YcI73bFykjN0DZdEvyzexDFY= X-Received: by 2002:a2e:3015:0:b0:2b9:ef0a:7d40 with SMTP id w21-20020a2e3015000000b002b9ef0a7d40mr1129280ljw.41.1691142590710; Fri, 04 Aug 2023 02:49:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pawel Veselov Date: Fri, 4 Aug 2023 11:49:34 +0200 Message-ID: Subject: Re: PGConnection.getNotifications(0) doesn't block To: rob stone Cc: List Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > > I'm implementing a bit that is expected to wait for published channel > > notifications, > > and once there are any - process them. > > > > I'm using PGConnection.getNotifications(0), but that immediately > > returns an empty > > array, and doesn't block like JavaDoc says it should. > > > > I'm on 42.6.0. > > > > What am I missing? > > > > Thank you. > Have you read the JDBC docs > https://jdbc.postgresql.org/documentation/server-prepare > which has a section about Listen/Notify? I've read https://access.crunchydata.com/documentation/pgjdbc/42.1.1/listennotify.html instead. I've read the Listen/Notify section in https://jdbc.postgresql.org/documentation/server-prepare just now, which carries identical text. I've also read the JavaDocs for the method(s). All these sources agree or at least don't contradict that getNotifications(0) should block without conditions, and none mention that the connection must be in the IDLE transaction state. For that matter, even https://www.postgresql.org/docs/current/sql-listen.html doesn't say anything about the fact that notifications are only received/can be read if the connection is in that state. It only mentions that the transaction that executed LISTEN must be first committed for that connection to start seeing notifications (for subscribed channel). What I was effectively doing on that connection is: BEGIN LISTEN COMMIT BEGIN UPDATE xxx; I've created this for tracking: https://github.com/pgjdbc/pgjdbc/issues/2937