`Too many non-blocking read actions submitted at once. Please use coalesceBy, BoundedTaskExecutor...` when using `MavenDomUtil.createDomDependency`

Answered

I noticed in some case, IntelliJ report this error when adding Maven dependencies through `MavenDomUtil.createDomDependency` :

java.lang.Throwable: Too many non-blocking read actions submitted
at once. Please use coalesceBy, BoundedTaskExecutor or another way of limiting the number of concurrently running threads.: 11 with similar stack traces are currently active
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:182)
	at com.intellij.openapi.application.impl.SubmissionTracker.preventTooManySubmissions(SubmissionTracker.java:45)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.<init>(NonBlockingReadActionImpl.java:231)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl.submit(NonBlockingReadActionImpl.java:191)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeCollector.amendStateInBackground(SuggestedRefactoringChangeCollector.kt:94)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeCollector.nextSignature(SuggestedRefactoringChangeCollector.kt:42)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeListener$MyDocumentListener.performWhenAllCommitted(SuggestedRefactoringChangeListener.kt:288)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeListener$MyDocumentListener.access$performWhenAllCommitted(SuggestedRefactoringChangeListener.kt:189)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeListener$MyDocumentListener$documentChanged$1.invoke(SuggestedRefactoringChangeListener.kt:250)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeListener$MyDocumentListener$documentChanged$1.invoke(SuggestedRefactoringChangeListener.kt:189)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeListener$sam$java_lang_Runnable$0.run(SuggestedRefactoringChangeListener.kt)
	at com.intellij.psi.impl.PsiDocumentManagerBase.performWhenAllCommitted(PsiDocumentManagerBase.java:587)
	at com.intellij.psi.impl.PsiDocumentManagerBase.performWhenAllCommitted(PsiDocumentManagerBase.java:577)
	at com.intellij.refactoring.suggested.SuggestedRefactoringChangeListener$MyDocumentListener.documentChanged(SuggestedRefactoringChangeListener.kt:250)
	at jdk.internal.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.intellij.util.EventDispatcher.dispatchVoidMethod(EventDispatcher.java:120)
	at com.intellij.util.EventDispatcher.lambda$createMulticaster$1(EventDispatcher.java:85)
	at com.sun.proxy.$Proxy92.documentChanged(Unknown Source)
	at com.intellij.openapi.editor.impl.DocumentImpl.changedUpdate(DocumentImpl.java:917)
	at com.intellij.openapi.editor.impl.DocumentImpl.updateText(DocumentImpl.java:821)
	at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:662)
	at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:599)
	at com.intellij.psi.impl.PsiToDocumentSynchronizer.doCommitTransaction(PsiToDocumentSynchronizer.java:212)
	at com.intellij.psi.impl.PsiToDocumentSynchronizer.lambda$commitTransaction$1(PsiToDocumentSynchronizer.java:188)
	at com.intellij.psi.impl.PsiToDocumentSynchronizer.lambda$doSync$0(PsiToDocumentSynchronizer.java:106)
	at com.intellij.psi.impl.PsiToDocumentSynchronizer.performAtomically(PsiToDocumentSynchronizer.java:124)
	at com.intellij.psi.impl.PsiToDocumentSynchronizer.doSync(PsiToDocumentSynchronizer.java:106)
	at com.intellij.psi.impl.PsiToDocumentSynchronizer.commitTransaction(PsiToDocumentSynchronizer.java:188)
	at com.intellij.pom.core.impl.PomModelImpl.commitTransaction(PomModelImpl.java:197)
	at com.intellij.pom.core.impl.PomModelImpl.lambda$runTransaction$1(PomModelImpl.java:152)
	at com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:481)
	at com.intellij.pom.core.impl.PomModelImpl.lambda$runTransaction$2(PomModelImpl.java:104)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeNonCancelableSection$3(CoreProgressManager.java:222)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:698)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:646)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:237)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:221)
	at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:93)
	at com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:142)
	at com.intellij.psi.impl.source.tree.CompositeElement.replaceAllChildrenToChildrenOf(CompositeElement.java:641)
	at com.intellij.psi.impl.source.xml.XmlTextImpl.doSetValue(XmlTextImpl.java:168)
	at com.intellij.psi.impl.source.xml.XmlTextImpl.setValue(XmlTextImpl.java:160)
	at com.intellij.psi.impl.source.xml.XmlTagValueImpl.setText(XmlTagValueImpl.java:133)
	at com.intellij.psi.impl.source.xml.XmlTagValueImpl.setText(XmlTagValueImpl.java:108)
	at com.intellij.util.xml.impl.DomInvocationHandler.setTagValue(DomInvocationHandler.java:695)
	at com.intellij.util.xml.impl.DomInvocationHandler.lambda$setValue$0(DomInvocationHandler.java:134)
	at com.intellij.util.xml.impl.DomManagerImpl.runChange(DomManagerImpl.java:297)
	at com.intellij.util.xml.impl.DomInvocationHandler.setValue(DomInvocationHandler.java:134)
	at com.intellij.util.xml.impl.SetInvocation.invoke(SetInvocation.java:47)
	at com.intellij.util.xml.impl.DomInvocationHandler.invoke(DomInvocationHandler.java:658)
	at com.intellij.util.xml.GenericDomValue$$EnhancerByJetBrainsMainCglib$$2e754a1e.setStringValue(<generated>)
	at org.jetbrains.idea.maven.dom.MavenDomUtil.createDomDependency(MavenDomUtil.java:433)
at my.code <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:150) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:947) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:148) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:184) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:157) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:124)
...

 

However I am not really understanding what I am doing wrong here.

  • There's this message `11 with similar stack traces are currently active` but the code is only adding 4 dependencies.
  • There's no immediate possibility with `MavenDomUtil.createDomDependency` to use either coalesceBy, BoundedTaskExecutor at least to my understanding

I have seen this exception being raised in 2021.1.3 and the latest EAP 2021.3.

The action is still performed correctly however it raises a notification about this error.

2 comments
Comment actions Permalink

Please show/link your invocation code

0
Comment actions Permalink

Hi Yann

Here's the code I am dealing with, the `MavenDomUtil.createDomDependency` is called in the addDependency method.

These next line do do anything else. They receive a list of 4 coordinates (`List<MavenId> ids`), never more.

var models = SlowOperations.allowSlowOperations(() -> MavenDomUtil.collectProjectModels(project));
var documentManager = PsiDocumentManager.getInstance(project);
for (DomFileElement<MavenDomProjectModel> fileElement : models) {
Document document = documentManager.getDocument(fileElement.getFile());
if (document == null) {
continue;
}
CommandProcessor.getInstance().executeCommand(
project,
() -> {
WriteCommandAction.writeCommandAction(project, fileElement.getFile())
.withName("Adding deps")
.run(() -> addDependency(fileElement.getRootElement(),
getEditor(document),
project,
ids));
},
"Adding deps",
DocCommandGroupId.noneGroupId(document)
);

// Refresh the project with the changes
ExternalSystemProjectTracker.getInstance(project).scheduleProjectRefresh();
// Stop at the first found file
return;
}

and the utility methods

@NotNull
static Editor getEditor(Document document) {
EditorFactory editorFactory = EditorFactory.getInstance();

@NotNull Editor[] editors = editorFactory.getEditors(document);
if (editors.length > 0) {
return editors[0];
}
return editorFactory.createEditor(document);
}

static void addDependency(@NotNull MavenDomProjectModel mavenModel,
@NotNull Editor editor,
@NotNull Project project,
@NotNull List<@NotNull MavenId> ids) {

PsiDocumentManager.getInstance(project).commitAllDocuments();
var managedDependencies = GenerateManagedDependencyAction.collectManagingDependencies(mavenModel);
MavenDomDependencies dependencies = mavenModel.getDependencies();
List<MavenId> deps = listActualDependencies(dependencies);

for (MavenCoordinate each : ids) {
var conflictId = new DependencyConflictId(each.getGroupId(),
each.getArtifactId(),
null,
null);
var managedDependenciesDom = managedDependencies.get(conflictId);

// Only add the dependency if they aren't declared yet
if (managedDependenciesDom == null
&& deps.stream().noneMatch(dep -> dep.equals(each.getGroupId(), each.getArtifactId()))) {
// createDomDependency may throw on 2021.1.3 : Too many non-blocking read actions submitted at once. Please use coalesceBy, BoundedTaskExecutor or another way of limiting the number of concurrently running threads.: 11 with similar stack traces are currently active
MavenDomUtil.createDomDependency(dependencies, editor, each);
}
}
}


private static List<MavenId> listActualDependencies(@NotNull MavenDomDependencies dependencies) {
var dependenciesXmlElement = dependencies.getXmlElement();
if (dependenciesXmlElement == null) {
return Collections.emptyList();
}
var tags = SyntaxTraverser.psiTraverser(dependenciesXmlElement)
.filter(XmlTag.class)
.filter(c -> c.getName().equals("dependency"))
.collect()
.toList();

var coordinates = new ArrayList<MavenId>();
for (XmlTag tag : tags) {
var groupId = tag.findFirstSubTag("groupId");
var artifactId = tag.findFirstSubTag("artifactId");
if (groupId != null && artifactId != null) {
coordinates.add(new MavenId(groupId.getValue().getTrimmedText(),
artifactId.getValue().getTrimmedText(), ""));
}
}
return coordinates;
}

 

 

 

 

 

0

Please sign in to leave a comment.