javamysqljdbcmariadb

'unexpected end of stream, read 0 bytes from 4' thrown by MariaDB stored procedure


We have a stored procedure in MariaDB that runs fine on the server, however when we run it from a client with JDBC we get the first rows but later it always fails with:

unexpected end of stream, read 0 bytes from 4 (socket was closed by server)

The table loan_balances2 is not too big, around 600K rows.  This is the stored procedure, do you see any issues? thanks! 

CREATE PROCEDURE `get_loan_balances_sample`()

BEGIN

drop table if exists all_loan_ids;
drop table if exists random_loan_ids;

create table all_loan_ids as select distinct loan_id from loan_balances2;
create table random_loan_ids as select * from all_loan_ids order by RAND() limit 50;

SELECT * FROM loan_balances2
where loan_id in (select Loan_ID from random_loan_ids)
order by Loan_ID, balance_date;

END

Solution

  • It is usually net_write_timeout . Server closes the socket, if your application is not reading data as fast as the server writes them. net_write_timeout defines, in seconds, how long server can stuck trying to send the result set. You can increase that limit, it is a session variable. This also appears in the MariaDB JDBC's FAQ