menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

Mutual exclusion in API calls

July 30, 2019 at 9:33am

Mutual exclusion in API calls

July 30, 2019 at 9:33am
Hi folks, I'm running into a problem when invoking workspace.updateWorkspaceFolders() twice in a row. The problem is that the the code in workspaceService.spliceRoots() is not concurrency-safe, but my two invocations seem to be running concurrently. Is there a some policy about running api requests in parallel? How can we enforce thread-safety here?

July 30, 2019 at 12:13pm
Hi, what kind of bad effects you get?
Is this such a hard question or is spectrum broken?
the first operation wins over the second?
Ok, so spectrum was broken:
you get a dialog asking whether you want to overwrite the workspace file. It's an out-of-sync problem.
the algorithm is
readWorkspaceFile
update workspace
write workspaceFile
the problem is that both executions get to "readWorkspaceFile" before the first gets to "writeWorkspaceFile"
we need a queue there to apply workspace modifications in proper order
Generally, how is concurrency handled in Theia?
generally we have queues in places where code is async but should be handled as an atomic operation
Edited
if it is sync code, then there is nothing to worry about
i don't think though that it is only about splitRoots, we need to make sure that all apis which modifie a workspace-file is thread-safe
Edited
Maybe it's a good idea to offer some library code for solving such problems.
we could generalize as a class into promise-util in core
the hardest part usually is not a queue, but finding all places where it should be called to make sure that non thread-safe apis are not exposed to the client
Edited
please open an issue for it