question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expected to read 4 header bytes but only received 0.

See original GitHub issue

The issue

This error is thrown on SaveChanges in one Web Api Action, every time. Other Actions don’t have this issue. I am updating about 20 entries in this SaveChanges, more than in others. After getting this error in this one place a few times, other actions also starts throwing it. After a few seconds they go back to normal.

I am using the latest MySQL on Google Cloud, and I am using SSL for connections. I am surprised at how little info on this issue is on the web, and this seems to be a completely generic error.

connect_timeout 10 delayed_insert_timeout 300 have_statement_timeout YES innodb_flush_log_at_timeout 1 innodb_lock_wait_timeout 50 innodb_rollback_on_timeout OFF interactive_timeout 28800 lock_wait_timeout 31536000 net_read_timeout 30 net_write_timeout 600 rpl_stop_slave_timeout 31536000 slave_net_timeout 30 wait_timeout 28800

Exception message: Stack trace:

System.IO.EndOfStreamException: Expected to read 4 header bytes but only received 0.
   at MySqlConnector.Protocol.Serialization.ProtocolUtility.<DoReadPayloadAsync>g__AddContinuation|5_0(ValueTask`1 readPacketTask, BufferedByteReader bufferedByteReader, IByteHandler byteHandler, Func`1 getNextSequenceNumber, ArraySegmentHolder`1 previousPayloads, ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) in /_/src/MySqlConnector/Protocol/Serialization/ProtocolUtility.cs:line 476
   at MySqlConnector.Core.ServerSession.ReceiveReplyAsyncAwaited(ValueTask`1 task) in /_/src/MySqlConnector/Core/ServerSession.cs:line 943

Further technical details

MySQL version: 8.0.18-google Pomelo.EntityFrameworkCore.MySql version: 6.0.1 Microsoft.AspNetCore.App version: 6.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
SavoInfostreamcommented, Jan 28, 2022

Well, I have found a bug in MySQL. One of my commands was a DELETE command which was causing the error. Google Cloud MySql log was showing: “The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains information that should help you find out what is causing the crash.”

Anyways, this DELETE statement would try to delete a row from a table, and do a CASCADE delete from another table (foreign key). Besides cascade delete, another interesting thing is that the child table has a multi-valued index on one of its json columns. These two things combined, with or without transaction, crash the MySql.

If I delete the child row manually, it works. If I drop the index and delete the parent row, it deletes the parent and the child row.

Thanks for the help, everyone. I will try and report this to MySql people.

0reactions
lauxjpncommented, Jan 29, 2022

@SavoInfostream Nice detective work! Thanks for letting us know and for reporting it to the MySQL team.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expected to read 4 header bytes but only received 0 #540
Hello Bradley, I met a exception in my production environment, the exception message is the title. Environment: MySqlConnector Version : 0.40.4.
Read more >
Expected to read 4 header bytes but only received 0
I have written a windows service which uses SSH (Secure Shell) to copy data from a CSV file to PhpMyAdmin online database.
Read more >
Stored procedure returns Expected to read 4 header bytes but ...
Stored procedure returns Expected to read 4 header bytes but only received 0. I have the following Stored Procedure: CREATE DEFINER=`user11`@`%` PROCEDURE ...
Read more >
Why do MySQL requests fail with the error “Expected to read 4 ...
Why do MySQL requests fail with the error “Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost”?
Read more >
Stored procedure returns Expected to read 4 header bytes but ...
Comments - Stored procedure returns Expected to read 4 header bytes but only received 0 ... Is DimDate a ColumnStore table? Which server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found