jshiell / checkstyle-idea

CheckStyle plug-in for IntelliJ IDEA
https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
Other
887 stars 161 forks source link

InterruptedException in DirectByteBufferAllocator / Future when opening existing IntelliJ project #620

Closed thomas-k-git closed 1 year ago

thomas-k-git commented 1 year ago

in current latest version 5.82.0

ByteBuffer allocation in dedicated thread was interrupted

  java.lang.InterruptedException
at java.base/java.util.concurrent.FutureTask.awaitDone(FutureTask.java:418)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:190)
at com.intellij.util.io.DirectByteBufferAllocator.allocate(DirectByteBufferAllocator.java:43)
at com.intellij.util.io.DirectByteBufferAllocator.allocateNewBuffer(DirectByteBufferAllocator.java:126)
at com.intellij.util.io.DirectByteBufferAllocator.allocate(DirectByteBufferAllocator.java:122)
at com.intellij.util.io.DirectBufferWrapper.allocateAndLoadFileContent(DirectBufferWrapper.java:235)
at com.intellij.util.io.DirectBufferWrapper.<init>(DirectBufferWrapper.java:65)
at com.intellij.util.io.FilePageCache.allocateAndLoadPage(FilePageCache.java:491)
at com.intellij.util.io.FilePageCache.get(FilePageCache.java:221)
at com.intellij.util.io.PagedFileStorage.doGetBufferWrapper(PagedFileStorage.java:463)
at com.intellij.util.io.PagedFileStorage.getBufferWrapper(PagedFileStorage.java:435)
at com.intellij.util.io.PagedFileStorage.getReadOnlyBuffer(PagedFileStorage.java:430)
at com.intellij.util.io.PagedFileStorage.get(PagedFileStorage.java:290)
at com.intellij.util.io.PagedFileStorage.getInt(PagedFileStorage.java:186)
at com.intellij.util.io.storage.AbstractRecordsTable.getSize(AbstractRecordsTable.java:189)
at com.intellij.util.io.storage.AbstractStorage.lambda$readBytes$5(AbstractStorage.java:275)
at com.intellij.util.ConcurrencyUtil.withLock(ConcurrencyUtil.java:246)
at com.intellij.util.io.storage.AbstractStorage.withReadLock(AbstractStorage.java:448)
at com.intellij.util.io.storage.AbstractStorage.readBytes(AbstractStorage.java:274)
at com.intellij.util.io.storage.RefCountingContentStorageImpl.lambda$internalReadStream$0(RefCountingContentStorageImpl.java:79)
at com.intellij.util.ConcurrencyUtil.withLock(ConcurrencyUtil.java:246)
at com.intellij.util.io.storage.AbstractStorage.withReadLock(AbstractStorage.java:448)
at com.intellij.util.io.storage.RefCountingContentStorageImpl.internalReadStream(RefCountingContentStorageImpl.java:79)
at com.intellij.util.io.storage.RefCountingContentStorageImpl.readStream(RefCountingContentStorageImpl.java:68)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSContentAccessor.readContentDirectly(PersistentFSContentAccessor.java:56)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSContentAccessor.readContent(PersistentFSContentAccessor.java:45)
at com.intellij.openapi.vfs.newvfs.persistent.FSRecordsImpl.readContent(FSRecordsImpl.java:1014)
at com.intellij.openapi.vfs.newvfs.persistent.FSRecords.readContent(FSRecords.java:411)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.readContent(PersistentFSImpl.java:339)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.contentsToByteArray(PersistentFSImpl.java:648)
at com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl.contentsToByteArray(VirtualFileImpl.java:124)
at com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl.contentsToByteArray(VirtualFileImpl.java:116)
at com.intellij.openapi.fileEditor.impl.LoadTextUtil.loadText(LoadTextUtil.java:511)
at com.intellij.openapi.fileEditor.impl.LoadTextUtil.loadText(LoadTextUtil.java:491)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerBase.loadText(FileDocumentManagerBase.java:104)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerBase.getDocument(FileDocumentManagerBase.java:60)
at com.intellij.openapi.fileEditor.FileDocumentManager.getDocument(FileDocumentManager.java:61)
at com.intellij.psi.impl.PsiDocumentManagerBase.getDocument(PsiDocumentManagerBase.java:173)
at org.infernus.idea.checkstyle.checker.PsiFileValidator.hasDocument(PsiFileValidator.java:45)
at org.infernus.idea.checkstyle.checker.PsiFileValidator.isScannable(PsiFileValidator.java:36)
at org.infernus.idea.checkstyle.checker.ScannableFile.lambda$createAndValidate$0(ScannableFile.java:79)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1707)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.infernus.idea.checkstyle.checker.ScannableFile.lambda$createAndValidate$2(ScannableFile.java:86)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:923)
at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:76)
at org.infernus.idea.checkstyle.checker.ScannableFile.createAndValidate(ScannableFile.java:87)
at org.infernus.idea.checkstyle.checker.ScanFiles.checkFiles(ScanFiles.java:204)
at org.infernus.idea.checkstyle.checker.ScanFiles.processFilesForModuleInfoAndScan(ScanFiles.java:166)
at org.infernus.idea.checkstyle.checker.ScanFiles.call(ScanFiles.java:82)
at org.infernus.idea.checkstyle.checker.ScanFiles.call(ScanFiles.java:35)
at com.intellij.openapi.application.impl.ApplicationImpl$3.call(ApplicationImpl.java:303)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
at java.base/java.lang.Thread.run(Thread.java:833)
thomas-k-git commented 1 year ago

idea.log

jshiell commented 1 year ago

Thanks very much, I'll have a look (although it might be next weekend at this point)

thomas-k-git commented 1 year ago

As always, thanks Jamie!

jshiell commented 1 year ago

Alas, looks like this is happening in the IDEA internals, where the code has no way to recover from an interruption in the buffer allocation. As far as I can tell there's little we can do at the plugin level. Sorry!

IDEA-319309:

...the real problem is that in some places we just have no good strategy to deal with thread interruption: e.g. in this case DirectByteBufferAllocator uses dedicated thread to allocate new DirectByteBuffer because of tricky behaviour of Linux system allocator -- interruption of this 'deferred allocation' task forces us allocate the Buffer in a current thread, which triggers Linux to allocate thread-local memory pool of quite a big size, uselessly spending JVM native memory limit on it.

It would be better, for sure, would all our code be ready/safe for thread interruption.