Bug #115959 Unable to locate recent stack traces in a large error log.
Submitted: 29 Aug 2024 9:53 Modified: 29 Aug 2024 10:41
Reporter: Yichang SONG (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:8.0.39 OS:Any
Assigned to: CPU Architecture:Any

[29 Aug 2024 9:53] Yichang SONG
Description:
The function sql/server_component/log_source_backtrace.cc:log_error_read_backtrace_loop() is designed to search for recent stack traces within the error log. However, if mysqld restarts with an enormous error log that includes a stack trace, this function fails to perform as expected.

The issue stems from improper usage of the function my_fseek() in sql/server_component/log_source_backtrace.cc:425. While my_fseek() returns MY_FILEPOS_ERROR to indicate an error, the log_error_read_backtrace_loop() function mistakenly interprets all return values greater than zero as errors.

How to repeat:
A code analysis will reveal the underlying error easily.
To replicate the issue, create a sufficiently large error log that triggers the condition size > max_backtrace.

Suggested fix:
sql/server_component/log_source_backtrace.cc:425
Modify
  if (my_fseek(fh, (long)pos, SEEK_SET))
as
  if (my_fseek(fh, (long)pos, SEEK_SET) == MY_FILEPOS_ERROR)
[29 Aug 2024 10:41] MySQL Verification Team
Hello Yichang Song,

Thank you for the report and test case.

regards,
Umesh