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

fix: store/rootmulti: correctly dispatch exporter closing while in a loop #14027

Merged

Conversation

odeke-em
Copy link
Collaborator

@odeke-em odeke-em commented Nov 25, 2022

The prior code used defers in a loop as a precaution for if any error was encountered in the loop then later invoked exporter.Close() at the bottom of the loop. However, that's a precarious situation that is entirely be fixed by using a closure and the defer .Close() as well.

An illustration for avoiding defers in a loop: https://go.dev/play/p/i3y1emcxNZK
as they won't correctly run.

Fixes #14026

@odeke-em odeke-em requested a review from a team as a code owner November 25, 2022 23:38
…loop

The prior code used defers in a loop as a precaution for if any error
was encountered in the loop then later invoked exporter.Close() at the
bottom of the loop. However, that's a precarious situation that is
entirely be fixed by using a closure and the defer .Close() as well.

An illustration for avoiding defers in a loop: https://go.dev/play/p/i3y1emcxNZK
as they won't correctly run.

Fixes #14026
@odeke-em odeke-em force-pushed the store-rootmulti-fix-Store.Snapshot-defers-misuse-in-loop branch from 5819ca4 to 3eb30f1 Compare November 25, 2022 23:39
Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud
Copy link

[Cosmos SDK] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

80.0% 80.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@odeke-em odeke-em enabled auto-merge (squash) November 29, 2022 08:26
@odeke-em odeke-em merged commit 5a1fa2e into main Nov 29, 2022
@odeke-em odeke-em deleted the store-rootmulti-fix-Store.Snapshot-defers-misuse-in-loop branch November 29, 2022 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants