Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgkjL-0004DZ-Li for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 23:19:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TgkjK-0002PB-JR for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 23:19:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgkbL-0002JQ-WD for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 23:11:32 +0000 Received: from news.hub.org ([200.46.204.72]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgkbI-00031Y-8H for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 23:11:31 +0000 Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.5/8.14.5) with ESMTP id qB6NBQeB083747 for ; Thu, 6 Dec 2012 19:11:26 -0400 (AST) (envelope-from news@news.hub.org) Received: from news.hub.org (news@localhost) by news.hub.org (8.14.5/8.14.5/Submit) with NNTP id qB6MvXCE080613 for pgsql-jdbc@postgresql.org; Thu, 6 Dec 2012 18:57:33 -0400 (AST) (envelope-from news) Received: by 10.68.191.97 with SMTP id gx1mr732108pbc.4.1354834652628; Thu, 06 Dec 2012 14:57:32 -0800 (PST) Received: by 10.50.212.69 with SMTP id ni5mr1230128igc.5.1354834652534; Thu, 06 Dec 2012 14:57:32 -0800 (PST) X-Newsgroups: pgsql.interfaces.jdbc Date: Thu, 6 Dec 2012 14:57:32 -0800 (PST) In-Reply-To: <51765e16-c35e-412d-b2f4-f8ab1a67f2f3@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.42.209.109; posting-account=Y2aaMAoAAABH9DJbJzVnp21hz7eFNnF7 References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> <50C0E09A.4070408@ttc-cmc.net> <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> <5a57e55f-1b8f-4f37-a271-af9fb1a9ffab@googlegroups.com> <016e01cdd3f5$1dbdaaf0$593900d0$@yahoo.com> <51765e16-c35e-412d-b2f4-f8ab1a67f2f3@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Statement.setQueryTimeout() with autoCommit=false From: =?UTF-8?Q?Pavel_Arno=C5=A1t?= Injection-Date: Thu, 06 Dec 2012 22:57:32 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable To: pgsql-jdbc@postgresql.org X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org I think that this is the reason why it doesn't work: https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/jdbc2/AbstractJ= dbc2Statement.java#L561 INSERT command is executed (immediately) and timer is canceled (also immedi= ately), so there is no guard against query timeout when transaction is comm= ited. That's unfortunate, for me at least. On Thursday, December 6, 2012 10:17:34 PM UTC+1, Pavel Arno=C5=A1t wrote: > I added e.printStackTrace() to catch block, just to be sure, and no excep= tion is thrown. I described result poorly, code with TimerTask does not *ti= meouts*, it *ends* after 5 seconds without error, just like my first exampl= e without explicit transaction and autoCommit set to true. >=20 >=20 >=20 > According to javadoc, st.cancel() after st.execute() should be ok. >=20 >=20 >=20 > Does someone use synchronous replication? Without query timeouts, it's no= t very usable IMO. >=20 >=20 >=20 > On Thursday, December 6, 2012 10:03:17 PM UTC+1, "David Johnston" wrote: >=20 > > It may be that I am wrong and at the moment haven't tested your example= s but >=20 > >=20 >=20 > > it seems odd that you can st.cancel() after st.execute() without getting >=20 > >=20 >=20 > > some kind of exception (which you are ignoring in your catch block). >=20 > >=20 >=20 > > Without some more detail I either need to do some testing on my own or = leave >=20 > >=20 >=20 > > it to more qualified individuals to help. I'll admit I am making untes= ted >=20 > >=20 >=20 > > assumptions here about how the interaction should behave (but often my = idea >=20 > >=20 >=20 > > of "should behave" differs from reality). >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > David J. >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > > -----Original Message----- >=20 > >=20 >=20 > > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- >=20 > >=20 >=20 > > > owner@postgresql.org] On Behalf Of Pavel Arno=C4=8F=C5=BC=CB=9Dt >=20 > >=20 >=20 > > > Sent: Thursday, December 06, 2012 3:33 PM >=20 > >=20 >=20 > > > To: pgsql-jdbc@postgresql.org >=20 > >=20 >=20 > > > Subject: Re: [JDBC] Statement.setQueryTimeout() with autoCommit=3Dfal= se >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > If that's how it works, why this code timeouts after 5 seconds?: >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > -- >=20 > >=20 >=20 > > > Connection conn =3D DriverManager.getConnection(url, props); >=20 > >=20 >=20 > > > conn.setAutoCommit(false); >=20 > >=20 >=20 > > > final PreparedStatement st =3D conn.prepareStatement("INSERT = INTO >=20 > >=20 >=20 > > test >=20 > >=20 >=20 > > > VALUES('xxx')"); >=20 > >=20 >=20 > > > st.setQueryTimeout(5); >=20 > >=20 >=20 > > > st.execute(); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > Timer timer =3D new Timer(true); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > TimerTask cancelTimer =3D new TimerTask() { >=20 > >=20 >=20 > > > public void run() { >=20 > >=20 >=20 > > > try { >=20 > >=20 >=20 > > > st.cancel(); >=20 > >=20 >=20 > > > } catch (SQLException e) { } >=20 > >=20 >=20 > > > } >=20 > >=20 >=20 > > > }; >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > timer.schedule(cancelTimer, 5000); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > conn.commit(); >=20 > >=20 >=20 > > > -- >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > Quick look at AbstractJdbc2Statement.execute() shows me that >=20 > >=20 >=20 > > > setQueryTimeout() works with Timer/TimerTask like this one. >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > Thanks, >=20 > >=20 >=20 > > > Pavel >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > On Thursday, December 6, 2012 7:36:53 PM UTC+1, "David Johnston" wrot= e: >=20 > >=20 >=20 > > > > > -----Original Message----- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > owner@postgresql.org] On Behalf Of dmp >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Sent: Thursday, December 06, 2012 1:15 PM >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > To: pgsql-jdbc@postgresql.org >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Cc: pavel.arnost@loutka.cz >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Subject: Re: [JDBC] Statement.setQueryTimeout() with >=20 > >=20 >=20 > > > > > autoCommit=3Dfalse >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Exactly. >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > According to the Java API: >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > void setAutoCommit(boolean autoCommit) throws SQLException >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Sets this connection's auto-commit mode to the given state. = If >=20 > >=20 >=20 > > > > > a >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > connection is in auto-commit mode, then all its SQL statements wi= ll >=20 > >=20 >=20 > > > > > be >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > executed and committed as individual transactions. Otherwise, its >=20 > >=20 >=20 > > > > > SQL >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > statements are grouped into transactions that are terminated by a >=20 > >=20 >=20 > > > > > call to >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > either the method commit or the method rollback. By default, new >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > connections are in auto-commit mode. >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > By setting setAutoCommit(false) you are deciding to tell the >=20 > >=20 >=20 > > > > > database your >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > code will determine when to commit the transaction. Thereby I wou= ld >=20 > >=20 >=20 > > > > > say >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > overiding setQueryTimeout(). >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > danap. >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > Even within an manually administered transaction the setting of >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > "setQueryTimeout()" will (should?) act on the individual statements >=20 > >=20 >=20 > > > > that >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > make up the transaction. If any individual statement within the >=20 > >=20 >=20 > > > > transaction >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > exceeds the limit that statement will fail and thus put the >=20 > >=20 >=20 > > > > transaction into >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > a "failed" state where a rollback (possibly to savepoint) is requir= ed. >=20 > >=20 >=20 > > > > The >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > transaction itself does not constitute a statement and as such it c= an >=20 > >=20 >=20 > > > > run >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > indefinitely long regardless of the presence of a statement timeout. >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > David J. >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Dave Cramer wrote: >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > Why would the query timeout at all ? >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > The query timeout is for long running queries. If the query tak= es >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > longer than n seconds it will timeout. >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > Dave >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > Dave Cramer >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > dave.cramer(at)credativ(dot)ca >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > http://www.credativ.ca >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > On Thu, Dec 6, 2012 at 12:04 PM, =20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > > wrote: >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > Hi, >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > does setQueryTimeout work with autoCommit=3Dfalse? When >=20 > >=20 >=20 > > > > > > autoCommit >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > is >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > true, this code timeouts after 5 seconds (as expected): >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > ~ >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > ~ >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > ~ >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > -- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > But if I set autoCommit to false, this code timeouts after = 30 >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > seconds on read timeout: >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > -- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > ~ >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > ~ >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > ~ >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > -- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > I'm confused what's setQueryTimeout() method for, why it >=20 > >=20 >=20 > > > > > > doesn't >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > > work with manual transactions? >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > -- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To m= ake >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > changes >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > to your subscription: >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > -- >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > To make changes to your subscription: >=20 > >=20 >=20 > > > > >=20 > >=20 >=20 > > > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > -- >=20 > >=20 >=20 > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make >=20 > >=20 >=20 > > changes >=20 > >=20 >=20 > > > to your subscription: >=20 > >=20 >=20 > > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > --=20 >=20 > >=20 >=20 > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >=20 > >=20 >=20 > > To make changes to your subscription: >=20 > >=20 >=20 > > http://www.postgresql.org/mailpref/pgsql-jdbc --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc