Skip to content

Commit beba585

Browse files
authored
Fix #19524: Protect use of HeaderIdGenerator with synchronized. (#19884)
Hopefully this is the only source of the race condition that we have been observing.
2 parents 9cc9107 + dc6b3cd commit beba585

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SectionRenderingExtension.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ object SectionRenderingExtension extends HtmlRenderer.HtmlRendererExtension:
3535
val idSuffix = repeatedIds.getOrElseUpdate((c, headerText), 0)
3636
val ifSuffixStr = if(idSuffix == 0) then "" else idSuffix.toString
3737
repeatedIds.update((c, headerText), idSuffix + 1)
38-
val id = idGenerator.getId(headerText + ifSuffixStr)
38+
39+
/* #19524 flexmark's `HeaderIdGenerator` does not appear to be thread-safe,
40+
* so we protect its usage with a full `synchronize`.
41+
*/
42+
val id = idGenerator.synchronized {
43+
idGenerator.getId(headerText + ifSuffixStr)
44+
}
45+
3946
val anchor = AnchorLink(s"#$id")
4047
val headerClass: String = header.getLevel match
4148
case 1 => "h500"

0 commit comments

Comments
 (0)