Re: [dbcp2] No error/warning when returning a connection twice
I think the important point for connection pols is, that a double close is not harming a returned „physical“ connection. This is done by throwing away the logical checked out wrapper connection - disassociating it from the pooled one. (And also never exposing the physical connection, which is a problem with the unwrap API) If that is done, the wrapper can basically chose how to behave: compatible (ignore the close after it is disassociated with the pooled physical connection) or log a warning or even throw — I see no harm in offering all 3 options. But the first property (do not reuse wrapper connections) is absolutely crucial for corruption protection (and also for Timeouts, cancels and reconnects). I haven’t checked dhcp, but i can’t imagine it does not do that correctly. Gruss Bernd -- http://bernd.eckenfels.net Von: Gary Gregory Gesendet: Wednesday, April 14, 2021 9:59:50 PM An: Commons Users List Betreff: Re: [dbcp2] No error/warning when returning a connection twice Hi, That's a tough sell IMO because (1) the JDBC specification does not require this behavior AND (2) it would break existing applications. What is the harm is having nothing happen when you close a closed connection? What am I missing? Gary On Wed, Apr 14, 2021, 14:47 Christopher Schultz < ch...@christopherschultz.net> wrote: > All, > > I have had an application for years which I run in development with > maxsize=1 so I can catch any double-check-out errors as soon as they > might read their ugly heads. > > But I never considered double-return logic errors. > > I recently wrote a "single connection pool" which is bare-bones and just > creates a single JDBC connection and hands it out to anyone who wants > it. It counts borrows vs returns and it was vomiting whenever we called > a particular method which, evidently, has been double-closing > connections for years. > > I had expected that DBCP2 would be objecting to double-closes, but > evidently not. > > I checked, and there is no configuration that I can find to enable some > kind of error/notification when double-closes are performed. > > Is that something the project would be interested in adding? > > I'm talking about something like this: > > Connection conn = dbcp.getConnection(); > > // do stuff > > conn.close(); // great, returns to pool > conn.close(); // should bomb > > Thanks, > -chris > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > >
Re: [dbcp2] No error/warning when returning a connection twice
Phil, On 4/14/21 16:39, Phil Steitz wrote: On 4/14/21 12:59 PM, Gary Gregory wrote: Hi, That's a tough sell IMO because (1) the JDBC specification does not require this behavior AND (2) it would break existing applications. What is the harm is having nothing happen when you close a closed connection? That was the thinking when we changed this to the current behavior back in 1.3. See https://issues.apache.org/jira/browse/DBCP-233 Thanks for the archeology on this one, Phil. I see that this has been considered in the past and it was determined that JDBC-spec-compliance made the most sense. I certainly see the logic in that. What am I missing? Gary, I'm trying to write the cleanest code I can, and if a tool like DBCP2 can help me fix my sloppy resource-management, all the better. Would there be scope in making this an optional check, similar to the "log abandoned" features that are opt-in? I always get my Connection objects from the same method in my own code, so I could wrap them in a proxy which keeps track of its closed-ness, but I figured this could be useful to a wider audience. Thanks, -chris - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
RE: [dbcp2] No error/warning when returning a connection twice
In fact, the Javadoc for Connection.close says clearly that calling close after a connection is already closed is a no-op. I think Chris is out of luck. https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Connection.html#close() > -Original Message- > From: Phil Steitz > Sent: Wednesday, April 14, 2021 3:40 PM > To: user@commons.apache.org > Subject: Re: [dbcp2] No error/warning when returning a connection twice > > > On 4/14/21 12:59 PM, Gary Gregory wrote: > > Hi, > > > > That's a tough sell IMO because (1) the JDBC specification does not > > require this behavior AND (2) it would break existing applications. > > What is the harm is having nothing happen when you close a closed > connection? > > That was the thinking when we changed this to the current behavior back in > 1.3. See > https://urldefense.com/v3/__https://issues.apache.org/jira/browse/DBCP- > 233__;!!F9svGWnIaVPGSwU!4ZHhXqqLrSYmRh4X25n2bE0fw9- > J8e3ueMXNalxPEBVQgE6skRKzKb6xYgBpsspi-ZlRMAk$ > > Phil > > > > > What am I missing? > > > > Gary > > > > > > On Wed, Apr 14, 2021, 14:47 Christopher Schultz < > > ch...@christopherschultz.net> wrote: > > > >> All, > >> > >> I have had an application for years which I run in development with > >> maxsize=1 so I can catch any double-check-out errors as soon as they > >> might read their ugly heads. > >> > >> But I never considered double-return logic errors. > >> > >> I recently wrote a "single connection pool" which is bare-bones and > >> just creates a single JDBC connection and hands it out to anyone who > >> wants it. It counts borrows vs returns and it was vomiting whenever > >> we called a particular method which, evidently, has been > >> double-closing connections for years. > >> > >> I had expected that DBCP2 would be objecting to double-closes, but > >> evidently not. > >> > >> I checked, and there is no configuration that I can find to enable > >> some kind of error/notification when double-closes are performed. > >> > >> Is that something the project would be interested in adding? > >> > >> I'm talking about something like this: > >> > >> Connection conn = dbcp.getConnection(); > >> > >> // do stuff > >> > >> conn.close(); // great, returns to pool conn.close(); // should bomb > >> > >> Thanks, > >> -chris > >> > >> - > >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > >> For additional commands, e-mail: user-h...@commons.apache.org > >> > >> > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org
Re: [dbcp2] No error/warning when returning a connection twice
On 4/14/21 12:59 PM, Gary Gregory wrote: Hi, That's a tough sell IMO because (1) the JDBC specification does not require this behavior AND (2) it would break existing applications. What is the harm is having nothing happen when you close a closed connection? That was the thinking when we changed this to the current behavior back in 1.3. See https://issues.apache.org/jira/browse/DBCP-233 Phil What am I missing? Gary On Wed, Apr 14, 2021, 14:47 Christopher Schultz < ch...@christopherschultz.net> wrote: All, I have had an application for years which I run in development with maxsize=1 so I can catch any double-check-out errors as soon as they might read their ugly heads. But I never considered double-return logic errors. I recently wrote a "single connection pool" which is bare-bones and just creates a single JDBC connection and hands it out to anyone who wants it. It counts borrows vs returns and it was vomiting whenever we called a particular method which, evidently, has been double-closing connections for years. I had expected that DBCP2 would be objecting to double-closes, but evidently not. I checked, and there is no configuration that I can find to enable some kind of error/notification when double-closes are performed. Is that something the project would be interested in adding? I'm talking about something like this: Connection conn = dbcp.getConnection(); // do stuff conn.close(); // great, returns to pool conn.close(); // should bomb Thanks, -chris - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [dbcp2] No error/warning when returning a connection twice
Hi, That's a tough sell IMO because (1) the JDBC specification does not require this behavior AND (2) it would break existing applications. What is the harm is having nothing happen when you close a closed connection? What am I missing? Gary On Wed, Apr 14, 2021, 14:47 Christopher Schultz < ch...@christopherschultz.net> wrote: > All, > > I have had an application for years which I run in development with > maxsize=1 so I can catch any double-check-out errors as soon as they > might read their ugly heads. > > But I never considered double-return logic errors. > > I recently wrote a "single connection pool" which is bare-bones and just > creates a single JDBC connection and hands it out to anyone who wants > it. It counts borrows vs returns and it was vomiting whenever we called > a particular method which, evidently, has been double-closing > connections for years. > > I had expected that DBCP2 would be objecting to double-closes, but > evidently not. > > I checked, and there is no configuration that I can find to enable some > kind of error/notification when double-closes are performed. > > Is that something the project would be interested in adding? > > I'm talking about something like this: > > Connection conn = dbcp.getConnection(); > > // do stuff > > conn.close(); // great, returns to pool > conn.close(); // should bomb > > Thanks, > -chris > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > >
[dbcp2] No error/warning when returning a connection twice
All, I have had an application for years which I run in development with maxsize=1 so I can catch any double-check-out errors as soon as they might read their ugly heads. But I never considered double-return logic errors. I recently wrote a "single connection pool" which is bare-bones and just creates a single JDBC connection and hands it out to anyone who wants it. It counts borrows vs returns and it was vomiting whenever we called a particular method which, evidently, has been double-closing connections for years. I had expected that DBCP2 would be objecting to double-closes, but evidently not. I checked, and there is no configuration that I can find to enable some kind of error/notification when double-closes are performed. Is that something the project would be interested in adding? I'm talking about something like this: Connection conn = dbcp.getConnection(); // do stuff conn.close(); // great, returns to pool conn.close(); // should bomb Thanks, -chris - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org