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

OCPBUGS-50476: v2/cli: always stop local registry and close registry.log #1068

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

r4f4
Copy link
Contributor

@r4f4 r4f4 commented Feb 5, 2025

Description

The local registry was not being gracefully shutdown and in some cases the registry.log file was closed while logrus was still trying to write to it:

2025/02/05 21:50:45  [INFO]   : mirror time     : 29.768175677s
2025/02/05 21:50:45  [INFO]   : 👋 Goodbye, thank you for using oc-mirror
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed

Github / Jira issue:

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code Improvements (Refactoring, Performance, CI upgrades, etc)
  • Internal repo assets (diagrams / docs on github repo)
  • This change requires a documentation update on openshift docs

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Expected Outcome

Please describe the outcome expected from the tests.

Copy link

openshift-ci bot commented Feb 5, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: r4f4
Once this PR has been reviewed and has the lgtm label, please assign aguidirh for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

if o.registryLogFile != nil {
// NOTE: we cannot just close the registry.log file as it is set as logrus output, which could still be in use
// by other dependencies before we exit. First we need to make sure logrus uses a different output.
logrus.SetOutput(io.Discard)
Copy link
Contributor

Choose a reason for hiding this comment

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

@r4f4 - good one, this has been a lingering problem

@lmzuccarelli
Copy link
Contributor

@r4f4 - Thanks for this update, improves our user experience and proper shutdown of the local registry and logs

The local registry was not being gracefully shutdown and in some cases
the `registry.log` file was closed while `logrus` was still trying to
write to it:
```
2025/02/05 21:50:45  [INFO]   : mirror time     : 29.768175677s
2025/02/05 21:50:45  [INFO]   : 👋 Goodbye, thank you for using oc-mirror
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
```
@r4f4 r4f4 force-pushed the always-close-registry-log branch from 4217ffa to 25f0600 Compare February 6, 2025 08:51
@r4f4
Copy link
Contributor Author

r4f4 commented Feb 6, 2025

Update: fixed unit tests.

@r4f4
Copy link
Contributor Author

r4f4 commented Feb 9, 2025

/retitle OCPBUGS-50476: v2/cli: always stop local registry and close registry.log

@openshift-ci openshift-ci bot changed the title v2/cli: always stop local registry and close registry.log OCPBUGS-50476: v2/cli: always stop local registry and close registry.log Feb 9, 2025
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Feb 9, 2025
@openshift-ci-robot
Copy link

@r4f4: This pull request references Jira Issue OCPBUGS-50476, which is invalid:

  • expected the bug to target the "4.19.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Description

The local registry was not being gracefully shutdown and in some cases the registry.log file was closed while logrus was still trying to write to it:

2025/02/05 21:50:45  [INFO]   : mirror time     : 29.768175677s
2025/02/05 21:50:45  [INFO]   : 👋 Goodbye, thank you for using oc-mirror
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed
Failed to write to log, write /oc-mirror-issue-ret/working-dir/logs/registry.log: file already closed

Github / Jira issue:

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code Improvements (Refactoring, Performance, CI upgrades, etc)
  • Internal repo assets (diagrams / docs on github repo)
  • This change requires a documentation update on openshift docs

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Expected Outcome

Please describe the outcome expected from the tests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Feb 9, 2025
@r4f4
Copy link
Contributor Author

r4f4 commented Feb 9, 2025

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Feb 9, 2025
@openshift-ci-robot
Copy link

@r4f4: This pull request references Jira Issue OCPBUGS-50476, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.19.0) matches configured target version for branch (4.19.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @zhouying7780

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested a review from zhouying7780 February 9, 2025 11:36
@r4f4
Copy link
Contributor Author

r4f4 commented Feb 9, 2025

/test e2e

Copy link

openshift-ci bot commented Feb 9, 2025

@r4f4: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

// stopLocalRegistry - stops the local registry and closes the registry.log file
func (o *ExecutorSchema) stopLocalRegistry(ctx context.Context) {
// Try to gracefully shutdown the local registry
ctx, cancel := context.WithTimeout(ctx, time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

@r4f4 - +1 using context

@lmzuccarelli
Copy link
Contributor

Verified locally using m2d d2m & m2m

@lmzuccarelli
Copy link
Contributor

/lgtm
/label acknowledge-critical-fixes-only

@openshift-ci openshift-ci bot added the acknowledge-critical-fixes-only Indicates if the issuer of the label is OK with the policy. label Feb 11, 2025
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 11, 2025
@lmzuccarelli
Copy link
Contributor

@r4f4 - I will wait for QE before adding the correct labels

Copy link
Contributor

@aguidirh aguidirh left a comment

Choose a reason for hiding this comment

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

Thanks @r4f4, a lot of good improvements.

I left only one comment, please let me know if you have questions about it.

Comment on lines -811 to -812
interruptSig := NormalStorageInterruptErrorf("end of mirroring to disk. Stopping local storage to prepare the archive")
o.localStorageInterruptChannel <- interruptSig
Copy link
Contributor

Choose a reason for hiding this comment

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

The tar ball generated in the end of m2d is the data under ~/.oc-mirror/.cache. Since this data is used by the local registry running on top of oc-mirror cache, to avoid data corruption, it is better to stop the local registry before starting the preparation of the tarball.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that the previous interrupt was not stopping the registry. But I can add the logic here. So this is only needed for the Mirror2Disk workflow, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it seems we cannot stop the registry as the blob collector for the tarball still accesses the registry: https://github.com/openshift/oc-mirror/blob/main/v2/internal/pkg/archive/image-blob-gatherer.go#L24

2025/02/11 15:12:20  [INFO]   : === Results ===
2025/02/11 15:12:20  [INFO]   :  ✓  193 / 193 release images mirrored successfully
2025/02/11 15:12:20  [INFO]   : 📦 Preparing the tarball archive...
2025/02/11 15:12:24  [WARN]   : Close registry.log failed: close /prjs/mirrors/oc-mirror-ocpbugs-49990/data/working-dir/logs/registry.log: file already closed
2025/02/11 15:12:24  [INFO]   : 👋 Goodbye, thank you for using oc-mirror
2025/02/11 15:12:24  [ERROR]  : unable to add image blobs to the archive : unable to find blobs corresponding to docker://localhost:55000/openshift/release:4.16.1-x86_64-ovirt-machine-controllers: pinging container registry localhost:55000: Get "http://localhost:55000/v2/": dial tcp [::1]:55000: connect: connection refused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledge-critical-fixes-only Indicates if the issuer of the label is OK with the policy. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants