Bug 64809 - Connection properties not reset to defaults when Connection is returned to the pool
Summary: Connection properties not reset to defaults when Connection is returned to th...
Status: NEW
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-13 09:40 UTC by xiongchao
Modified: 2020-10-13 10:13 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description xiongchao 2020-10-13 09:40:58 UTC
it's  haven't reset connection properties based on connectionpool configuration information when returnConnection

Causes the connection pool properties to be confused

if A thread  connection A con.setReadOnly(true) con.setAutoCommit(false),release connection A。

B thread get connection A execute update throws exception
Comment 1 Mark Thomas 2020-10-13 10:02:29 UTC
Correcting product (I'm assuming jdbc-pool on the basis I've confirmed DBCP does reset these properties)
Comment 2 xiongchao 2020-10-13 10:13:49 UTC
 protected void returnConnection(PooledConnection con) {
        if (this.isClosed()) {
            this.release(con);
        } else {
            if (con != null) {
                try {
                    this.returnedCount.incrementAndGet();
                    con.lock();
                    if (con.isSuspect()) {
                        if (this.poolProperties.isLogAbandoned() && log.isInfoEnabled()) {
                            log.info("Connection(" + con + ") that has been marked suspect was returned." + " The processing time is " + (System.currentTimeMillis() - con.getTimestamp()) + " ms.");
                        }

                        if (this.jmxPool != null) {
                            this.jmxPool.notify("SUSPECT CONNECTION RETURNED", "Connection(" + con + ") that has been marked suspect was returned.");
                        }
                    }

                    if (this.busy.remove(con)) {
                        if (!this.shouldClose(con, 2)) {
                            con.setStackTrace((String)null);
                            con.setTimestamp(System.currentTimeMillis());
                            if (this.idle.size() >= this.poolProperties.getMaxIdle() && !this.poolProperties.isPoolSweeperEnabled() || !this.idle.offer(con)) {
                                if (log.isDebugEnabled()) {
                                    log.debug("Connection [" + con + "] will be closed and not returned to the pool, idle[" + this.idle.size() + "]>=maxIdle[" + this.poolProperties.getMaxIdle() + "] idle.offer failed.");
                                }

                                this.release(con);
                            }
                        } else {
                            if (log.isDebugEnabled()) {
                                log.debug("Connection [" + con + "] will be closed and not returned to the pool.");
                            }

                            this.release(con);
                        }
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Connection [" + con + "] will be closed and not returned to the pool, busy.remove failed.");
                        }

                        this.release(con);
                    }
                } finally {
                    con.unlock();
                }
            }

        }
    }