Fix deadlock issue with custom Enum implementation#802
Merged
stevedlawrence merged 1 commit intoapache:mainfrom Jun 16, 2022
Merged
Fix deadlock issue with custom Enum implementation#802stevedlawrence merged 1 commit intoapache:mainfrom
stevedlawrence merged 1 commit intoapache:mainfrom
Conversation
Our Enum implementation use for property values/lookups has important benefits over Scala Enumerations. However, it seems like the way we implement it can lead to circular deadlocks. When a Value is initialized it causes the Enum to be initialized. And the Enum initialized calls forceConstruction to initialized all the Values. This leads to circular instantiating that works in most cases, but sometimes leads to a deadlock. Where this deadlock exists or how to fix it is not clear. It's also not clear what changed to make this deadlock much more likely. To avoid this, we this change removes the forceConstruction function and replaces it with a manually managed Array of Enum Values. This Array is lazily evaluated so that instantiated an Enum does not also directly instantiate the Enum Value, avoiding the circular deadlock. This does require extra code to define an Enum, but the majority of Enums are in generated code so doesn't add much maintenance burden. DAFFODIL-2704
tuxji
approved these changes
Jun 15, 2022
Contributor
tuxji
left a comment
There was a problem hiding this comment.
+1
Thanks for fixing this issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Our Enum implementation use for property values/lookups has important
benefits over Scala Enumerations. However, it seems like the way we
implement it can lead to circular deadlocks. When a Value is initialized
it causes the Enum to be initialized. And the Enum initialized calls
forceConstruction to initialized all the Values. This leads to circular
instantiating that works in most cases, but sometimes leads to a
deadlock. Where this deadlock exists or how to fix it is not clear. It's
also not clear what changed to make this deadlock much more likely.
To avoid this, we this change removes the forceConstruction function and
replaces it with a manually managed Array of Enum Values. This Array is
lazily evaluated so that instantiated an Enum does not also directly
instantiate the Enum Value, avoiding the circular deadlock. This does
require extra code to define an Enum, but the majority of Enums are in
generated code so doesn't add much maintenance burden.
DAFFODIL-2704