Error 'Received resultset tuples, but no field structure for them' on queries subsequent to an error

From: Christina Simpson <csimpson(at)xmatters(dot)com>
To: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Error 'Received resultset tuples, but no field structure for them' on queries subsequent to an error
Date: 2017-11-15 17:24:45
Message-ID: EFF4BB98-7350-426A-A8B7-4284E3C5F061@xmatters.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi. I am working through an upgrade of JDBC drivers to version 42.1.4. After the upgrade we were getting the following error in one of our tests. It was only occurring when several tests were run together and running the failing test by itself passed.

The error is:

java.lang.IllegalStateException: Received resultset tuples, but no field structure for them
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2121)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:117)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:692)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:711)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:154)

I’ve been able to simplify the test failures with some possibly interesting results and have narrowed down the failure to use a single select query that contains a UUID (it is cast as a uuid in the query) but we are passing to spring jdbc template as a string. If exactly the fifth query contains an invalid uuid, the query fails as expected with this stack

Caused by: org.postgresql.util.PSQLException: ERROR: invalid input syntax for uuid: "0b74c00c"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2477)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:117)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:692)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)

I can trace through with the debugger and see that after the query fails, the cached statement is added back to the statement cache and the value for fields is reset to null.

It looks to be set to null in this method org.postgresql.core.v3.QueryExecutorImpl#sendParse

The next query to take that query out of the cache fails with the first error above. At first I thought it was extremely odd that this had to be exactly the fifth query but as I was debugging I noticed that at the value of prepareThreshold is 5.

This is smelling like a possible bug but I wanted to check with the experts. I can attempt to provide some more simplified code sample if needed but am hoping it may be easily reproduced with this report. I haven’t seen this error reported exactly like this but have seen some reports of people reporting this error then reporting that it just went away. Which might make sense if failed queries are getting released to the query cache and the fields values are reset but never set again but once that query falls off the LRU cache the problem goes away. I haven’t been able to find a work around yet but would love suggestions to try. Thanks.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thach Hoang 2017-11-15 19:30:25 [pgjdbc/pgjdbc] 279fb4: fix: always return Short[] for java.sql.Array.getA...
Previous Message Michael Paquier 2017-11-14 08:55:45 Re: [JDBC] [HACKERS] Channel binding support for SCRAM-SHA-256