Skip to content

Conversation

chrisguitarguy
Copy link
Contributor

What this PR does / why we need it: So the defer cancel() runs. Go won't run defers if os.Exit() is called, so in the case of an error the context cancelation will not run. See https://go.dev/play/p/0AIokfnVk0m for an example. Probably not a big deal, but something I noticed poking around the source code while exploring oras and thought I would send this small PR.

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test? Nope
  • Does this change require a documentation update? No
  • Does this introduce breaking changes that would require an announcement or bumping the major version? No
  • Do all new files have an appropriate license header? n/a

So the `defer cancel()` runs. Go won't run defers if `os.Exit()` is
called, so in the case of an error the context cancelation will not run.

Signed-off-by: Christopher Davis <cdavis9999@gmail.com>
Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.42%. Comparing base (3b495b1) to head (7df98e2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1658   +/-   ##
=======================================
  Coverage   84.41%   84.42%           
=======================================
  Files         125      125           
  Lines        5661     5663    +2     
=======================================
+ Hits         4779     4781    +2     
  Misses        627      627           
  Partials      255      255           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

Nice catch! LGTM

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@shizhMSFT shizhMSFT changed the title refactor: Split a run and main function so defers Execute refactor: split a run and main function so defers Execute Mar 14, 2025
@shizhMSFT shizhMSFT merged commit e90e21a into oras-project:main Mar 14, 2025
8 checks passed
@chrisguitarguy chrisguitarguy deleted the run_defer branch March 14, 2025 18:58
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 this pull request may close these issues.

3 participants