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
Eliminate race condition for edit/close/open cmds #6998
Eliminate race condition for edit/close/open cmds #6998
Conversation
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.
I like this approach 👍
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.
Approving as harmless, but I don't see what this PR actually changes except doing some stylistic refactorings. How it is supposed to eliminate race condition? That remains a mystery to me.
engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/AsynchronousCommand.scala
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/SynchronousCommand.scala
Outdated
Show resolved
Hide resolved
...untime/src/main/scala/org/enso/interpreter/instrument/execution/CommandExecutionEngine.scala
Outdated
Show resolved
Hide resolved
There was an inherent race condition between edit, close & open commands which could not be prevented solely using locks. `EditFileCmd` triggered `EnsureCompiledJob` which was applying edits collected over time. At the same `CloseFileCmd` and `OpenFileCmd` were executed asynchronously and required locks on compilation unit and file lock. Additionally, open file was resetting the module's runtime source irrespective of any edits that could already have been applied with the asynchronous execution in `EnsureCompiledJob`. This was visible especially during early manipulation of the project when open/close was performed due to a bug in IDE (#6843). Now commands can be run either synchronously or asynchronously. Only that way can we ensure that `close` & `open` commands finish by the time any editions are being applied to module's sources.
d634725
to
400b07f
Compare
This PR also helps with the
error that people were reporting occasionally. |
This change partially reverts #6998 which introduced synchronous commands to a) avoid deadlocks b) ensure the correct execution of close/open commands c) avoid data corruption when applying edits. Sadly, it now turns out that the possibility of synchronous commands is at odds with how commands are expected to execute. More importantly, there are commands comming from Language Server but there are commands comming from Runtime as well. When combined with context locks it creates an environment for deadlocks as described in #7898. This change ensures that commands are always executed asynchronously but also we can also mark some commands to preserve the order of execution wrt to their submission. That way no deadlocks arise and there is do data corruption of the enso code.
This change partially reverts #6998 which introduced synchronous commands to a) avoid deadlocks b) ensure the correct execution of close/open commands c) avoid data corruption when applying edits. Sadly, it now turns out that the possibility of synchronous commands is at odds with how commands are expected to execute. More importantly, there are commands comming from Language Server but there are commands comming from Runtime as well. When combined with context locks it creates an environment for deadlocks as described in #7898. This change ensures that commands are always executed asynchronously but also we can also mark some commands to preserve the order of execution wrt to their submission. That way no deadlocks arise and there is do data corruption of the enso code.
This change partially reverts #6998 which introduced synchronous commands to a) avoid deadlocks b) ensure the correct execution of close/open commands c) avoid data corruption when applying edits. Sadly, it now turns out that the possibility of synchronous commands is at odds with how commands are expected to execute. More importantly, there are commands comming from Language Server but there are commands comming from Runtime as well. When combined with context locks it creates an environment for deadlocks as described in #7898. This change ensures that commands are always executed asynchronously but also we can also mark some commands to preserve the order of execution wrt to their submission. That way no deadlocks arise and there is do data corruption of the enso code.
Rather than using an overly complicated locking mechanism switched to a `BlockingQueue` and a separate thread pool quaranteeing that commands are executed in order but they are also non-blocking. This change partially reverts #6998 which introduced synchronous commands to a) avoid deadlocks b) ensure the correct execution of close/open commands c) avoid data corruption when applying edits. Sadly, it now turns out that the possibility of synchronous commands is at odds with how commands are expected to execute. More importantly, there are commands comming from Language Server but there are commands comming from Runtime as well. When combined with context locks it creates an environment for deadlocks as described in #7898.
Pull Request Description
There was an inherent race condition between edit, close & open commands which could not be prevented solely using locks.
EditFileCmd
triggeredEnsureCompiledJob
which was applying edits collected over time. At the sameCloseFileCmd
andOpenFileCmd
were executed asynchronously and required locks on compilation unit and file lock.Additionally, open file was resetting the module's runtime source irrespective of any edits that could already have been applied with the asynchronous execution in
EnsureCompiledJob
. This was visible especially during early manipulation of the project when open/close was performed due to a bug in IDE (#6843).Now commands can be run either synchronously or asynchronously. Only that way can we ensure that
close
&open
commands finish by the time any editions are being applied to module's sources.Closes #6841.
Important Notes
In the given video,
"foo"
would be greyed out because it would never be part of the module's (runtime) sources. Therefore no IR would be generated for it or instrumentation, meaning it would be present inexpressionUpdates
information necessary for IDE.Kazam_screencast_00014.webm
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.