Add guard checks for isInPushedAnalysis to prevent undefined errors#211
Add guard checks for isInPushedAnalysis to prevent undefined errors#211anoek merged 1 commit intoonline-go:mainfrom
Conversation
Review FindingsI've analyzed this PR and found one issue that should be addressed: Bug: Incomplete race condition fix in OGSConnectivity.ts:551-552The guard check for Current code: if (typeof this.isInPushedAnalysis === "function" && this.isInPushedAnalysis()) {
this.leavePushedAnalysis(); // ⚠️ Can throw if deleted
}Suggested fix: if (typeof this.isInPushedAnalysis === "function" && this.isInPushedAnalysis()) {
if (typeof this.leavePushedAnalysis === "function") {
this.leavePushedAnalysis();
}
}The test should also be updated to verify this scenario by deleting both methods before calling the handler. |
Code Review FindingsAfter analyzing this PR, I found one bug that needs to be addressed: Bug: Missing guard for
|
Issues Found1. Inconsistent guard pattern with existing codeThe PR adds checks like: if (this.isInPushedAnalysis !== undefined && this.isInPushedAnalysis()) {However, other files (CanvasRenderer.ts and SVGRenderer.ts) use a different pattern: (typeof this.isInPushedAnalysis() !== "undefined" && this.isInPushedAnalysis())This is problematic because:
Locations affected:
2. RecommendationConsider fixing all instances to use the correct pattern: if (typeof this.isInPushedAnalysis !== 'undefined' && this.isInPushedAnalysis()) {This checks if the function exists before calling it, which is what you want to protect against the race condition. |
9614ac8 to
07c2981
Compare
PR ReviewAnalyzed this PR for bugs and performance issues. SummaryThe fix correctly addresses the race condition where socket events fire after isInPushedAnalysis is deleted during object destruction. No significant issues found. Analysis✅ Core fix is sound: The guards prevent calling undefined as a function NotesThe existing code in CanvasRenderer.ts and SVGRenderer.ts uses a different pattern that checks the return type of isInPushedAnalysis(), which would actually throw the same error if the function was deleted. Your fix is more correct. Those files likely don't encounter the race condition because rendering stops when the component is destroyed, whereas socket events can arrive asynchronously even after event handler cleanup begins. Recommendation: Approve and merge. |
Critical Bug in Type CheckThe guard checks added in this PR will not prevent the error. The condition: if (this.isInPushedAnalysis !== "undefined" && this.isInPushedAnalysis()) {is comparing the method to the string Expected behavior: The guard should prevent errors when Actual behavior: The current code will still throw
Solution: Use one of these correct patterns already used elsewhere in the codebase:
References:
|
Code ReviewI've analyzed this PR for bugs and performance issues. The fix correctly addresses the race condition where async socket events can fire after Issue Found: Inconsistent Pattern Across CodebaseThe same race condition exists in other files that weren't fixed in this PR: CanvasRenderer.ts:1283 and SVGRenderer.ts:1369, 2090, 3173 use the buggy pattern: typeof this.isInPushedAnalysis() !== "undefined"This checks the return value instead of checking if the function exists, so it will still throw errors if called after destruction. Recommendation: Apply the same fix pattern ( The fix in this PR is correct and the tests properly validate the behavior. The guards have negligible performance impact (typeof checks are extremely fast). |
Fixes race condition where async socket events fire after isInPushedAnalysis is deleted during object destruction.
|
I've completed a thorough review of this PR focusing on bugs and performance issues. The fix correctly addresses the race condition where async socket events can fire after |
|
Thanks for the catch! |
Error
this.isInPushedAnalysis is not a functionoccurs when the app was automatically switching between games.Fixed race condition where async socket events fire after isInPushedAnalysis is deleted during object destruction.