-
Notifications
You must be signed in to change notification settings - Fork 121
Исправлена потенциальная гонка при закрытии документа в BSLTextDocumentService. #3724
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 1 commit
67104f4
6b92861
e2c80ca
fb345fb
ff642f4
f8abc95
9f00ce2
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -530,9 +530,18 @@ public void didClose(DidCloseTextDocumentParams params) { | |||||||||||||||||||||||||||||||||
| // Wait for all queued changes to complete (with timeout to avoid hanging) | ||||||||||||||||||||||||||||||||||
| if (!docExecutor.awaitTermination(AWAIT_CLOSE, TimeUnit.SECONDS)) { | ||||||||||||||||||||||||||||||||||
| docExecutor.shutdownNow(); | ||||||||||||||||||||||||||||||||||
| // Must wait for worker thread to finish even after shutdownNow, | ||||||||||||||||||||||||||||||||||
| // because finally block in worker may still be executing flushPendingChanges | ||||||||||||||||||||||||||||||||||
| docExecutor.awaitTermination(1, TimeUnit.SECONDS); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } catch (InterruptedException e) { | ||||||||||||||||||||||||||||||||||
| docExecutor.shutdownNow(); | ||||||||||||||||||||||||||||||||||
| // Wait briefly for worker to finish after interrupt | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| docExecutor.awaitTermination(1, TimeUnit.SECONDS); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| } catch (InterruptedException ignored) { | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| docExecutor.awaitTermination(1, TimeUnit.SECONDS); | |
| } catch (InterruptedException ignored) { | |
| boolean terminated = docExecutor.awaitTermination(1, TimeUnit.SECONDS); | |
| if (!terminated) { | |
| log.warn( | |
| "Document executor for URI {} did not terminate within 1 second after interrupt during document close", | |
| uri | |
| ); | |
| } | |
| } catch (InterruptedException ignored) { | |
| log.warn( | |
| "Interrupted again while waiting for document executor for URI {} to terminate after shutdownNow", | |
| uri | |
| ); |
Copilot
AI
Jan 2, 2026
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.
The variable 'ignored' is declared but never used in the catch block. While this is a common pattern for documenting intentional suppression of exceptions, the variable should actually be named with an underscore prefix (e.g., '_') or simply omit the variable name entirely in modern Java, as the catch block already has explanatory logging that makes the intention clear.
| } catch (InterruptedException ignored) { | |
| } catch (InterruptedException _ignored) { |
Copilot
AI
Jan 2, 2026
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.
The logic for waiting after shutdownNow() is duplicated in two places - once inside the if block when normal termination times out (lines 534-542) and again in the catch block for InterruptedException (lines 547-561). Consider extracting this common logic into a private helper method to improve maintainability and reduce code duplication. The helper method could accept the URI and handle the awaitTermination call with appropriate logging.
Copilot
AI
Jan 2, 2026
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.
The added concurrency logic for handling race conditions during document closure lacks test coverage. The existing didClose test at line 183 in BSLTextDocumentServiceTest.java is very basic and doesn't test the scenario where pending changes are being flushed when shutdown occurs. Consider adding tests for: (1) didClose with pending changes in the executor queue, (2) didClose during an active didChange operation, (3) behavior when awaitTermination timeout expires.
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.
If the awaitTermination call at line 535 returns false (indicating the worker thread did not terminate within 1 second), the method proceeds without any logging or additional handling. This means the document closure continues while the worker thread might still be executing flushPendingChanges in its finally block, potentially leading to the race condition this change aims to fix. Consider logging this condition or implementing additional handling to ensure safe cleanup.