Fix deadlock issue with stdout tracer in tx-generator #5460
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.
Problem:
The root issue we encountered with the tx-generator was the creation of a new stdout backend for every tracer instance. This approach, however, conflicts with the fundamental requirement of having only one stdout backend per application. Consequently, this practice led to unnecessary garbage collection of these backends and resulted in the dreaded "BlockedIndefinitelyOnMVar" exception.
Solution:
To rectify this issue, the proposed solution involves constructing and utilizing only a single backend for all tracers. The introduction of a shutdown handler, in this context, becomes redundant. It's important to note that a shutdown handler wouldn't actually address the underlying problem but would merely mask it.
Alternative Consideration:
While it is conceivable to enforce a single instance from the trace-dispatcher library, this approach would necessitate the use of unsafePerformIO. We've chosen not to adopt this method due to concerns related to its contravariant interface.
This pull request aims to implement the solution by ensuring a single backend, thus resolving the issue and enhancing the stability of the tx-generator.
In addition we adopted the tracing of tx-generator to use the new interface, where it was possible. So the fix itself can be found in function initTxGenTracers.