When two threads execute this method concurrently (e.g., as part of two firings of didChange), the following race can happen:
currentContent = text1; // by thread 1
currentContent = text2; // by thread 2
currentTree = newContents(text2); // by thread 2
currentTree = newContents(text1); // by thread 1
// at this point, currentContent and currentTree are inconsistent
Depending on usage patterns, the reads of these fields (via the getters) might need synchronization as well.
Describe the bug
The fields in TextDocumentState are volatile but not race-free. For instance, in method
update
:https://github.com/usethesource/rascal-language-servers/blob/3051c6b95157a563f6fba1517127a580ed7a68a9/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/TextDocumentState.java#L63-L67
When two threads execute this method concurrently (e.g., as part of two firings of
didChange
), the following race can happen:Depending on usage patterns, the reads of these fields (via the getters) might need synchronization as well.