Bug #102258 Incorrect error while trying to download binary log from a certain position
Submitted: 15 Jan 2021 14:42 Modified: 18 Jan 2021 12:04
Reporter: Niranjan R Email Updates:
Status: Not a Bug Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.7 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any

[15 Jan 2021 14:42] Niranjan R
Incorrect error message reported when trying to download binary logs from an incorrect position.

[Linux]$ mysqlbinlog --read-from-remote-server --host=x.x.x.x --user=root --password=******** --result-file=bl.log mysql-bin-changelog.000003 --start-position 299
mysqlbinlog: [Warning] Using a password on the command line interface can be insecure.
ERROR: Got error reading packet from server: log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the first event 'mysql-bin-changelog.000003' at 299, the last event read from './mysql-bin-changelog.000003' at 123, the last byte read from './mysql-bin-changelog.000003' at 318.

The error message states that the issue is related to max_allowed _packet.
But, it isn't.

The download is successful if the "start position" is omitted, and if the entire file is downloaded

How to repeat:
Download a binary log by specifying a "random" position

For example:
mysql> show binlog events in 'mysql-bin-changelog.000003';
| mysql-bin-changelog.000003 | 298 | Query          |  12017812 |         401 | use `test`; insert into blog values(1029) |

Start position of the query is 298
End position is 401.

While downloading the binary log, specify the position as "299"   
$ mysqlbinlog --read-from-remote-server --host=x.x.x.x --user=root --password=******** --result-file=bl.log mysql-bin-changelog.000003 --start-position 299

And you'll get the error.

Based on my testing, I've noticed that we get this error each time we specify the start position to be "1" greater than the actual start position of a query
And it doesn't happen with all the positions that we specify. Few of the positions throw a proper error:
ERROR: Got error reading packet from server: bogus data in log event;

Same error is displayed if you set up replication using random binlog position.
The error is misleading and it should be corrected.
[15 Jan 2021 19:40] Simon Mudd
If you use the wrong binlog position all bets are off. The binlog stream is a binary streaam with a reasonably well defined format but there are no explicit message delimiters. The first part of the message includes its length, so if you jump into a random position this may make mysqlbinlog simply interpret the data as having a very large packet. That's wrong as the "input data" is wrong.

So special care is required to ensure and verify that the binlog position you specify is correct as otherwise correct processing is impossible given that the binlog file has no easy to recognise delimiters.
[18 Jan 2021 12:04] MySQL Verification Team

This is not a bug. If you use wrong position we cannot find the start/end and the read data can be (will be) larger than max packet size so the error is "correct".

all best