Skip to content
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

LockManager Synchronizing Runtime With Language Server #1890

Closed
6 of 7 tasks
radeusgd opened this issue Jul 20, 2021 · 0 comments · Fixed by #1972
Closed
6 of 7 tasks

LockManager Synchronizing Runtime With Language Server #1890

radeusgd opened this issue Jul 20, 2021 · 0 comments · Fixed by #1972
Assignees
Labels
-tooling Category: tooling p-high Should be completed in the next sprint

Comments

@radeusgd
Copy link
Member

radeusgd commented Jul 20, 2021

Summary

Once #1772 is fully implemented, both the Runtime's Compiler (when resolving imports) and the Language Server (on user's library/preinstall request) will be able to install libraries. If two processes try installing the same library at the same time, it can become corrupted or the process may fail - to avoid this we have a synchronization mechanism in place.

However due to JVM limitations, the FileLockManager can only synchronize distinct JVMs. To aid this, we created a ThreadSafeFileLockManager which, when shared within a single JVM, is able to synchronize threads within a single JVM and within distinct JVMs at the same time.

Our scenario however is more complicated - the Language Server and Runtime do run on the same JVM, but due to Classpath Separation, they cannot that easily share an instance of ThreadSafeFileLockManager.

This task consists of creating a LockManager conforming wrapper which will allow to synchronize installation operations happening on both sides - in the Language Server as well as the Runtime.

To achieve that, we need to create a wrapper for LockManager that will live in the runtime, which will use Truffle's serverTransport and MessageEndpoint reuse the RuntimeServerInstrument and its connection to communicate with a ThreadSafeLockManager instance running in the language-server.

It would be best to implement this before #1772.

Value

  • Libraries can be safely installed both in the Language Server and the Runtime.

Specification

  • Create a simple protocol for the lock manager.
  • Implement a LockManager which will use the MessageEndpoint to send lock requests and handle responses. It should ensure that it will be used from a single thread or should otherwise be thread-safe.
  • Use the serverTransport functionality to bind the MessageEndpoint to a service which will pass the aforementioned requests to the language server's instance of ThreadSafeLockManager.
  • Make it possible to send requests using RuntimeServerConnector in both directions.
  • Redirect lock requests to the LockManagerService which wraps an underlying ThreadSafeLockManager.
  • Create a ConnectedLockManager that connects to an Endpoint and passes the lock requests to the Language Server using the runtime connector mechanism.
  • When creating the context, if running in Language Server mode, connect to the LS's lock manager using the mechanism created above; in text mode create a local ThreadSafeFileLockManager.

Acceptance Criteria & Test Cases

  • The above specification has been completed.
  • Test the ConnectedLockManager by connecting it to the LockManagerService.
  • Manually test the language server with the IDE to make sure that nothing is broken.
@radeusgd radeusgd added Category: Backend -tooling Category: tooling p-high Should be completed in the next sprint labels Jul 20, 2021
@radeusgd radeusgd mentioned this issue Jul 22, 2021
28 tasks
@radeusgd radeusgd self-assigned this Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-tooling Category: tooling p-high Should be completed in the next sprint
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant