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

MGMT-16157 Remove recover usage from DB transactions #5795

Merged
merged 1 commit into from Dec 12, 2023

Conversation

filanov
Copy link
Contributor

@filanov filanov commented Dec 10, 2023

The downside of recover is that it may hide bugs like accessing nil pointer and can create a situation where a function panic and instead of returning an error it will return nil, in some cases it cause a hot loop in our controllers, or just move a bug to an upper later.

To avoid those situations we decided to remove the recover function usage in the transaction code and move to a new transaction style that will make scope of the transaction and handling of errors clearer.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci openshift-ci bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 10, 2023
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2023
@filanov
Copy link
Contributor Author

filanov commented Dec 10, 2023

I didn't removed all the old transaction style code because this is not the purpose of this PR, i will do it in another ticket.

@filanov
Copy link
Contributor Author

filanov commented Dec 10, 2023

An example of a code that can create strange issues

package main

import (
	"fmt"
)

func Foo() (*int, error) {
	i := 5
	var b *int

	defer func() {
		if r := recover(); r != nil {
			fmt.Println("foo recover")
		}
	}()

	fmt.Println("create a panic", *b)
	return &i, nil
}

func main() {
	i, err := Foo()
	if err != nil {
		panic("had an error")
	}

	fmt.Println(*i)
}

Copy link

codecov bot commented Dec 10, 2023

Codecov Report

Merging #5795 (8aea285) into master (f4bbcf6) will increase coverage by 0.17%.
Report is 1 commits behind head on master.
The diff coverage is 67.09%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5795      +/-   ##
==========================================
+ Coverage   67.88%   68.06%   +0.17%     
==========================================
  Files         235      235              
  Lines       34552    34414     -138     
==========================================
- Hits        23456    23424      -32     
+ Misses       9009     8928      -81     
+ Partials     2087     2062      -25     
Files Coverage Δ
internal/cluster/transition.go 73.86% <0.00%> (+1.63%) ⬆️
internal/operators/handler/handler.go 61.53% <0.00%> (+8.20%) ⬆️
internal/cluster/registrar.go 46.96% <43.75%> (-1.72%) ⬇️
internal/bminventory/inventory_v2_handlers.go 57.44% <45.00%> (+0.87%) ⬆️
internal/bminventory/inventory.go 71.52% <73.56%> (+1.08%) ⬆️

... and 1 file with indirect coverage changes

@filanov
Copy link
Contributor Author

filanov commented Dec 11, 2023

/retest

The downside of recover is that it may hide bugs like accessing nil
pointer and can create a situation where a function panic and instead of
returning an error it will return nil, in some cases it cause a hot loop
in our controllers, or just move a bug to an upper later.

To avoid those situations we decided to remove the recover function
usage in the transaction code and move to a new transaction style that
will make scope of the trnasaction and handling of errors clearer.

Fix unit tests

Remove CancelInstallCommitFailedEvent event, it doesn't help the user in any way
Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

Nice ratio
image

👍

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 11, 2023
Copy link

openshift-ci bot commented Dec 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carbonin, filanov

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

The pull request process is described 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

@filanov filanov added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Dec 12, 2023
Copy link

openshift-ci bot commented Dec 12, 2023

@filanov: 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/test-infra repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 005ba71 into openshift:master Dec 12, 2023
17 checks passed
@filanov filanov deleted the remove-recover branch December 12, 2023 12:01
@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

This PR has been included in build ose-agent-installer-api-server-container-v4.16.0-202312121444.p0.g005ba71.assembly.stream for distgit ose-agent-installer-api-server.
All builds following this will include this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants