Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalafix sbt causing OOM errors #1965

Closed
tgodzik opened this issue Mar 15, 2024 · 11 comments · Fixed by scalacenter/sbt-scalafix#405
Closed

Scalafix sbt causing OOM errors #1965

tgodzik opened this issue Mar 15, 2024 · 11 comments · Fixed by scalacenter/sbt-scalafix#405

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Mar 15, 2024

This started happening after the most recent release and always breaks on a stack trace:

java.lang.OutOfMemoryError: Java heap space
	at org.eclipse.jgit.internal.storage.file.PackIndexV2.<init>(PackIndexV2.java:95)
	at org.eclipse.jgit.internal.storage.file.PackIndex.read(PackIndex.java:101)
	at org.eclipse.jgit.internal.storage.file.PackIndex.open(PackIndex.java:67)
	at org.eclipse.jgit.internal.storage.file.Pack.idx(Pack.java:161)
	at org.eclipse.jgit.internal.storage.file.Pack.get(Pack.java:273)
	at org.eclipse.jgit.internal.storage.file.PackDirectory.open(PackDirectory.java:216)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openPackedObject(ObjectDirectory.java:393)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openPackedFromSelfOrAlternate(ObjectDirectory.java:356)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openObjectWithoutRestoring(ObjectDirectory.java:346)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openObject(ObjectDirectory.java:331)
	at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:132)
	at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:1119)
	at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:126)
	at org.eclipse.jgit.revwalk.RevWalk.markStart(RevWalk.java:308)
	at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:343)
	at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:180)
	at org.eclipse.jgit.api.LogCommand.call(LogCommand.java:133)
	at scalafix.internal.sbt.JGitCompletion.$anonfun$x$1$1(JGitCompletions.scala:29)
	at scalafix.internal.sbt.JGitCompletion$$Lambda$9375/0x00007ec7[2180](https://github.com/scalameta/metals/actions/runs/8298008580/job/22710386419#step:4:2181)8600.apply(Unknown Source)
	at scala.util.Try$.apply(Try.scala:213)
	at scalafix.internal.sbt.JGitCompletion.<init>(JGitCompletions.scala:29)
	at scalafix.internal.sbt.ScalafixCompletions.gitDiffParser$lzycompute(ScalafixCompletions.scala:119)
	at scalafix.internal.sbt.ScalafixCompletions.gitDiffParser(ScalafixCompletions.scala:118)
	at scalafix.internal.sbt.ScalafixCompletions.parser(ScalafixCompletions.scala:186)
	at scalafix.sbt.ScalafixPlugin$.$anonfun$scalafixInputTask$4(ScalafixPlugin.scala:357)
	at scalafix.sbt.ScalafixPlugin$$$Lambda$8642/0x00007ec7215f5600.apply(Unknown Source)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at scala.Function1$$Lambda$1172/0x00007ec7204dee78.apply(Unknown Source)

even if no scalafix task is actually run.

Were there any changes recently that could cause it?

@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 15, 2024

Maybe the jgit update broke things?

@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 15, 2024

@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 16, 2024

Or it might be scalameta/scalameta#3650 though it's curious the stack trace show ScalafixCompletions and scalafix is not even being run

@xuwei-k
Copy link
Contributor

xuwei-k commented Mar 23, 2024

I think jgit use too many memory.

here is profile memory result just launch sbt in my private large repository.

just launch sbt

if remove .git directory before launch sbt. for avoid isGitRepository == true

@xuwei-k
Copy link
Contributor

xuwei-k commented Mar 23, 2024

Or more likely https://github.com/scalacenter/sbt-scalafix/pull/378/files

Yes scalacenter/sbt-scalafix#378 remove scalafixCompletions from globalSettings. I think it generate many JGitCompletion instances

@bjaglin
Copy link
Collaborator

bjaglin commented Mar 23, 2024

Thanks for the report @tgodzik and for the fix @xuwei-k!

@xuwei-k
Copy link
Contributor

xuwei-k commented Mar 23, 2024

also jgit use many memory if repo is too many commits and/or many branch, tag.

I think JGitCompletions.scala should not retain jgit objects for avoid memory leak.

https://github.com/scalacenter/sbt-scalafix/blob/0ab8c2ce40b7021e0cc421020a48e00cba9aa66f/src/main/scala/scalafix/internal/sbt/JGitCompletions.scala#L21

  • refList is Seq[org.eclipse.jgit.lib.Ref]
  • refs is List[org.eclipse.jgit.revwalk.RevCommit]

see following reproduce repo

@bjaglin
Copy link
Collaborator

bjaglin commented Mar 23, 2024

also jgit use many memory if repo is too many commits and/or many branch, tag.

I think JGitCompletions.scala should not retain jgit objects for avoid memory leak.

Indeed, there is an inherent leak there, which predates sbt-scalafix 0.12.0.

I am on my phone right now so I cannot check, but I am unsure how the upper bound set by setMaxCount(20) causes so much memory consumption after the initial lookup.

In any case, feel free to open a follow-up PR 👍

@xuwei-k
Copy link
Contributor

xuwei-k commented Mar 26, 2024

workaround

-addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0")
+// TODO remove explicit "scalafix-interfaces" dependency if sbt-scalafix 0.12.1 released
+addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
+libraryDependencies += "ch.epfl.scala" % "scalafix-interfaces" % "0.12.0"

@xuwei-k
Copy link
Contributor

xuwei-k commented Apr 20, 2024

Any plans to release new version? 👀

@bjaglin
Copy link
Collaborator

bjaglin commented Apr 21, 2024

Yes! 2.13.14 is around the corner so I am holding the release a bit (to provide 2.13.14 compatibility in the testkit). Based on the current ETA, it should be last days of April.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants