Mutual exclusion in API calls
July 30, 2019 at 9:33amMutual exclusion in API calls
July 30, 2019 at 9:33amHi 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
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 we have queues in places where code is async but should be handled as an atomic operation
if it is sync code, then there is nothing to worry about
for example a queue in text editor model to handle concurrent save operations: https://github.com/theia-ide/theia/blob/555ba87f3d304a0667bb1e6e0674191e22b04c73/packages/monaco/src/browser/monaco-editor-model.ts#L192-L201
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-safethe 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