-
Notifications
You must be signed in to change notification settings - Fork 2
fix(qr+logging): resolve QR race condition, URL double messages, and EF Core log pollution #334
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using Serilog; | ||
|
|
||
| namespace TelegramSearchBot.Common { | ||
| /// <summary> | ||
| /// Shared logger holder for EF Core logging. | ||
| /// Initialized by TelegramSearchBot.Program and used by Database project. | ||
| /// </summary> | ||
| public static class LoggerHolders { | ||
| public static Serilog.ILogger EfCoreLogger { get; set; } = null!; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,11 +24,22 @@ public static async Task Process(string[] args) { | |||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
| var task = db.ListLeftPop("QRTasks").ToString(); | ||||||||||||||||||
| if (string.IsNullOrWhiteSpace(task)) { | ||||||||||||||||||
| Log.Logger.Warning("Empty task from QRTasks queue — skipping"); | ||||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
| var photoPath = db.StringGetDelete($"QRPost-{task}").ToString(); | ||||||||||||||||||
| if (string.IsNullOrWhiteSpace(photoPath)) { | ||||||||||||||||||
| Log.Logger.Warning("Empty QRPost key for task {task} — data not yet available or already consumed", task); | ||||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
| string response = string.Empty; | ||||||||||||||||||
| Log.Logger.Information("QR processing started: task={task}, path={path}", task, photoPath); | ||||||||||||||||||
| try { | ||||||||||||||||||
| response = await qr.ExecuteAsync(photoPath); | ||||||||||||||||||
| Log.Logger.Information("QR result: task={task}, len={len}, content={preview}", task, response?.Length ?? -1, response?.Length > 100 ? response.Substring(0, 100) + "..." : response); | ||||||||||||||||||
|
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging raw QR path/content at Info level Line 37 and Line 40 log Proposed fix-Log.Logger.Information("QR processing started: task={task}, path={path}", task, photoPath);
+Log.Logger.Information("QR processing started: task={task}", task);
-Log.Logger.Information("QR result: task={task}, len={len}, content={preview}", task, response?.Length ?? -1, response?.Length > 100 ? response.Substring(0, 100) + "..." : response);
+Log.Logger.Information("QR result: task={task}, len={len}", task, response?.Length ?? -1);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } catch (Exception ex) { | ||||||||||||||||||
| Log.Logger.Warning(ex, "QR processing failed for task {task}", task); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| db.StringSet($"QRResult-{task}", response); | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,9 @@ public async Task ExecuteAsync(PipelineContext p) { | |||||||||
| if (p.BotMessageType != BotMessageType.Message) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| _logger.LogInformation("AutoQR processing started for {ChatId}/{MessageId}", | ||||||||||
| e.Message.Chat.Id, e.Message.MessageId); | ||||||||||
|
|
||||||||||
| try { | ||||||||||
| var filePath = IProcessPhoto.GetPhotoPath(e); | ||||||||||
| if (filePath == null) { | ||||||||||
|
|
@@ -67,10 +70,13 @@ public async Task ExecuteAsync(PipelineContext p) { | |||||||||
| var qrStr = await _autoQRService.ExecuteAsync(filePath); | ||||||||||
|
|
||||||||||
| if (string.IsNullOrWhiteSpace(qrStr)) { | ||||||||||
| _logger.LogInformation("No QR code detected for {ChatId}/{MessageId}", | ||||||||||
| e.Message.Chat.Id, e.Message.MessageId); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| _logger.LogInformation("QR Code recognized for {ChatId}/{MessageId}. Content: {QrStr}", e.Message.Chat.Id, e.Message.MessageId, qrStr); | ||||||||||
| _logger.LogInformation("QR Code recognized for {ChatId}/{MessageId}. Content: {QrStr}, Length: {QrStrLen}", | ||||||||||
| e.Message.Chat.Id, e.Message.MessageId, qrStr, qrStr.Length); | ||||||||||
|
Comment on lines
+78
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not log raw QR content Line 78-79 logs Proposed fix-_logger.LogInformation("QR Code recognized for {ChatId}/{MessageId}. Content: {QrStr}, Length: {QrStrLen}",
- e.Message.Chat.Id, e.Message.MessageId, qrStr, qrStr.Length);
+_logger.LogInformation("QR Code recognized for {ChatId}/{MessageId}. Length: {QrStrLen}",
+ e.Message.Chat.Id, e.Message.MessageId, qrStr.Length);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| // Add QR result to processing results | ||||||||||
| p.ProcessingResults.Add($"[QR识别结果] {qrStr}"); | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publish a result before skipping an invalid payload
On Line 32-35,
continuedrops the task without settingQRResult-{task}. The caller inSubProcessService.RunRpcwaits for that key and will fail on timeout.Proposed fix
if (string.IsNullOrWhiteSpace(photoPath)) { Log.Logger.Warning("Empty QRPost key for task {task} — data not yet available or already consumed", task); + db.StringSet($"QRResult-{task}", string.Empty); continue; }📝 Committable suggestion
🤖 Prompt for AI Agents