You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DAP: Rerun of a debug session that still runs reports "Write-unsafe context" #2396
Rerun of a DAP debug session that is still running reports an internal error from TransactionGuard:
Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality state (not "any").
at com.intellij.openapi.application.TransactionGuardImpl.assertWriteActionAllowed
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments
at com.redhat.devtools.lsp4ij.dap.DAPDebugRunner.execute(DAPDebugRunner.java:84)
at com.intellij.execution.runners.AsyncProgramRunner$execute$1.invoke
...
at com.intellij.execution.impl.ExecutionManagerImpl$restartRunProfile$1.run
In tests, the logged error fails the run: "Error running '…': Write-unsafe context!". In the IDE, LOG.error doesn't throw, so the run most likely goes on, but IntelliJ reports an internal error at each such Rerun.
Why
The runner saves the documents:DAPDebugRunner.execute has called FileDocumentManager.saveAllDocuments() first since DAP support was added. IntelliJ's execution classes don't save them on that path, so the call is needed: the program may read the files.
Rerun starts from where saving isn't allowed: when the session still runs, ExecutionManagerImpl.restartRunProfile stops it, waits until its process has ended, and then runs the configuration again from an alarm, which isn't a write-safe context.
Not affected: a first run, and a Rerun after the session has ended, start from the action, which is write-safe.
Reproduce
Start a DAP debug session, and press Rerun in its tab while it runs. DAPRerunTest, in the fix, does it with an in-process DAP server and fails without the fix.
Activity