Skip to content

Add error logging for crc32 validation failures. #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pymysqlreplication/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import decimal
import zlib
import logging

from pymysqlreplication.constants.STATUS_VAR_KEY import *
from pymysqlreplication.exceptions import StatusVariableMismatch
Expand Down Expand Up @@ -57,7 +58,14 @@ def _verify_event(self):
data = self.packet.read(19 + self.event_size)
footer = self.packet.read(4)
byte_data = zlib.crc32(data).to_bytes(4, byteorder="little")
self._is_event_valid = True if byte_data == footer else False
if byte_data == footer:
self._is_event_valid = True
else:
self._is_event_valid = False
logging.error(
f"An CRC32 has failed for the event type {self.event_type}, "
"indicating a potential integrity issue with the data."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if byte_data == footer:
self._is_event_valid = True
else:
self._is_event_valid = False
logging.error(
f"An CRC32 has failed for the event type {self.event_type}, "
"indicating a potential integrity issue with the data."
)
self._is_event_valid = True if byte_data == footer else False
if not self._is_event_valid:
logging.error(
f"An CRC32 has failed for the event type {self.event_type}, "
"indicating a potential integrity issue with the data."
)

@why-arong
I think this looks more readable, what do you think?
I think the code you wrote is good, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that code reads better!

How about error message? Is there any additional information we can provide besides 'self.event_type'??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's enough

self.packet.read_bytes -= 19 + self.event_size + 4
self.packet.rewind(20)

Expand Down