Current transaction is committed, commands ignored until end of transaction block. What does this error mean?

I am getting an exception like below intermittently. Can someone let me know when can this exception come?

current transaction is committed, commands ignored until end of transaction block
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
        at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:133)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
        at com.vnera.storage.config.CockroachConfigStore.lambda$addProperty$0(CockroachConfigStore.java:44)
        at com.vnera.storage.config.CockroachConfigStore.tx(CockroachConfigStore.java:150)
        at 

Can someone let me know what does the error mean current transaction is committed, commands ignored until end of transaction block.. When can this error come?

Relevant code

   private void tx(final Connection conn, final Transaction tx) throws SQLException {
        final boolean prev = conn.getAutoCommit();
        conn.setAutoCommit(false);
        final Savepoint sp = conn.setSavepoint(SAVE_POINT);
        try {
            int i = 0;
            while (true) {
                try {
                    tx.exec(conn); // This line throwing exception
                    conn.releaseSavepoint(sp);
                } catch (SQLException e) {
                    if (!e.getSQLState().trim().equals("40001")) {
                        // cannot handle this exception, let the client know about it and handle it (possibly retry)
                        logger.error("transaction exception code " + e.getSQLState(), e);
                        return;
                    }
                    logger.warn("tx retrying {}th time", ++i);
                    conn.rollback(sp);   // Signal the database that we will attempt a retry.
                }
            }  // while transaction not completed or not failed.
        } finally {
            conn.commit();
            conn.setAutoCommit(prev);
        }
    }

protected void addProperty(
            ConfigKey key, String propertyName, long timeStamp, String escapedValue, String tableName) throws SQLException {
        try (final Connection conn = serverConnection.getConnection()) {
            final long s = System.currentTimeMillis();
            tx(conn, c -> {
                        final long nowTs = System.currentTimeMillis();
                        try (final PreparedStatement stmt = getStmtForAddProperty(conn, tableName, key, propertyName, timeStamp, escapedValue, nowTs)) {
                            stmt.executeUpdate(); // This line is throwing exception
                            track(stmt, nowTs, TAG_DB_QUERY_GROUP, "addPropTxT1", TAG_DB_TABLE, tableName, TAG_PROP_GROUP, propertyName);
                        }

                        // update cfg_version
                        final String q = "insert into " +
                                config.getVersionsTableName() +
                                " (customerId, objecttype, objectid, propertyname, timeinstant, updatetimestamp) " +
                                " values (?, ?, ?, ?, ?, ?) ";
                        try (final PreparedStatement stmt = conn.prepareStatement(q)) {
                            stmt.setInt(1, key.customerId);
                            stmt.setInt(2, key.objectType);
                            stmt.setLong(3, key.objectId);
                            stmt.setString(4, propertyName);
                            stmt.setLong(5, timeStamp);
                            stmt.setTimestamp(6, new Timestamp(nowTs));
                            stmt.executeUpdate();
                            track(stmt, nowTs, TAG_DB_QUERY_GROUP, "addPropTxT2", TAG_DB_TABLE, tableName, TAG_PROP_GROUP, propertyName);
                        }
                    }
            );
            track(null, s, TAG_DB_QUERY_GROUP, "addPropTx", TAG_DB_TABLE, tableName);
        }
    }

Hi @tuk. That error means you’re sending a sql command to a transaction that’s already been committed. I believe this is because you don’t exit the while(true) loop above if the statement was successful; you need a break after conn.releaseSavepoint(sp);

1 Like

Aaah … Thanks a lot @dan.