[CONJ-538] Could not read resultset: unexpected end of stream, read 0 bytes from 4 Created: 2017-10-12  Updated: 2019-07-06  Resolved: 2017-10-13

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 2.1.2
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Vladimir Kiselev Assignee: Diego Dupin
Resolution: Won't Do Votes: 0
Labels: None
Environment:

Client: Oracle Java 1.8.0_121
Server: Debian Jessie, MariaDB 10.2.9


Issue Links:
Relates
relates to CONJ-539 Better message when server close conn... Closed

 Description   

java.sql.SQLNonTransientConnectionException: (conn=27949) Could not send query: unexpected end of stream, read 0 bytes from 4
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:161) ~[billService.jar:1]
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:106) ~[billService.jar:1]
at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:235) ~[billService.jar:1]
at org.mariadb.jdbc.MariaDbPreparedStatementServer.executeInternal(MariaDbPreparedStatementServer.java:366) ~[billService.jar:1]
at org.mariadb.jdbc.MariaDbPreparedStatementServer.execute(MariaDbPreparedStatementServer.java:336) ~[billService.jar:1]
at org.mariadb.jdbc.MariaDbPreparedStatementServer.executeQuery(MariaDbPreparedStatementServer.java:315) ~[billService.jar:1]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[billService.jar:1]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[billService.jar:1]
at gsm.service.beeline.SOAPAPISync.getSubscriberByCTN(SOAPAPISync.java:47) ~[billService.jar:1]
at gsm.service.beeline.SyncPayments$Task.call(SyncPayments.java:74) [billService.jar:1]
at gsm.service.beeline.SyncPayments$Task.call(SyncPayments.java:40) [billService.jar:1]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: java.sql.SQLException: Could not send query: unexpected end of stream, read 0 bytes from 4
Query is: SELECT `SUBSCRIBERS`.`ID` AS `SUBSCRIBER_ID`,`SUBSCRIBERS_DOCS`.`ID` AS `DOCUMENT_ID` FROM `SUBSCRIBERS` LEFT JOIN `SUBSCRIBERS_DOCS` ON (`SUBSCRIBERS_DOCS`.`SUBSCRIBER_ID`=`SUBSCRIBERS`.`ID`) WHERE `CTN`=? LIMIT 1, parameters [9629850707]
at org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:146) ~[billService.jar:1]
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executePreparedQuery(AbstractQueryProtocol.java:929) ~[billService.jar:1]
at org.mariadb.jdbc.MariaDbPreparedStatementServer.executeInternal(MariaDbPreparedStatementServer.java:360) ~[billService.jar:1]
... 11 more
Caused by: java.io.EOFException: unexpected end of stream, read 0 bytes from 4
at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacketArray(StandardPacketInputStream.java:240) ~[billService.jar:1]
at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacket(StandardPacketInputStream.java:208) ~[billService.jar:1]
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1300) ~[billService.jar:1]
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1281) ~[billService.jar:1]
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executePreparedQuery(AbstractQueryProtocol.java:926) ~[billService.jar:1]
at org.mariadb.jdbc.MariaDbPreparedStatementServer.executeInternal(MariaDbPreparedStatementServer.java:360) ~[billService.jar:1]



 Comments   
Comment by Vladimir Kiselev [ 2017-10-13 ]

Please close!
I am sorry, it is my error
Thanks

Comment by Diego Dupin [ 2017-10-13 ]

Hi, I'll not close it, because Error message could be improved with a "connection closed by server".

Comment by Diego Dupin [ 2017-10-13 ]

Another task is created to improve error message CONJ-529

Comment by Jeffrey N Dyke [ 2018-02-20 ]

Just want to add a comment b/c i ran into this exact error and was confused by it.

In my case a connection was opened an initial query , another function ran that took a while and then i tried to use that connection again, but it failed to reach the server b/c of the timeout as stated, so consider what is being done in between your two database calls if you see this.

Hope this helps someone that stumbles on this.

Comment by Reece [ 2019-07-06 ]

Yip - also going to chime in cause this is the top ranked google result for this error. Kinda feel like a noob for saying this - but for me; I was doing bulk inserts (about 300k); e.g. a bunch of inserts inside a for/while loop; and didn't realize with the MariaDB connector (maybe all JDBC connectors?) you need to close your PreparedStatements and ResultSets after each use before re-assigning them; otherwise it creates a memory leak. I always figured that try, catch, finally (closing in finally) was enough; e.g. like re-assigning any other reference in Java to a variable, that the garbage collector would free things up for you. Ran my app while also running the linux 'top' command in another window, watched MariaDB memory consumption steadily climb to 60% of total memory in a minute or two and then this error popped up. After adding additional close statements throughout my loops, went away immediately; running the same code again, MariaDB memory consumption only climbed as high as 1.5% of total system resources.

Generated at Thu Feb 08 03:16:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.