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

Don't show context cancelled errors in attribute reader #19006

Merged

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 4, 2022

Fix #18997

Signed-off-by: Andrew Thornton art27@cantab.net

Fix go-gitea#18997

Signed-off-by: Andrew Thornton <art27@cantab.net>
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Mar 4, 2022
@lunny
Copy link
Member

lunny commented Mar 5, 2022

But we may need to log them?

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath force-pushed the fix-18997-dont-report-ctx-closed-errors branch from c5ca0af to dd9e22a Compare March 5, 2022 18:35
@zeripath
Copy link
Contributor Author

zeripath commented Mar 5, 2022

We don't need to log these.

The program being ended because the context has been cancelled is a normal thing and it should not be logged.

Similarly the "signal: killed" error will only occur due to the process being killed. This will happen due to context cancellation.

These are not errors and should not be logged.

@wxiaoguang
Copy link
Contributor

Why c.ctx.Err() is err means context is being cancelled, but not using Error() string matches "context canceled"?

The other expression below is using err.Error() matches "signal: killed" to mean the process was killed .....

@zeripath
Copy link
Contributor Author

zeripath commented Mar 6, 2022

What's your question here?

We can ignore both of these as they're expected errors.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 6, 2022

What's your question here?

We can ignore both of these as they're expected errors.

I was asking about the meaning about c.ctx.Err() != err. I still have difficulty to understand whether it is correct in all cases.

c.ctx.Err() != err is a very rare expression for this scenario, most developers just seldom see or use it.

Question 1: Is it really correct?

For example:

  • case 1: c.ctx.Err() = "context canceled" and err = "other error"?
  • case 2: c.ctx.Err() = "other error" and err = "context canceled"?
  • case 3: c.ctx.Err() = "the-error" and err = "the-error"?

Are they all correct for the expression c.ctx.Err() != err?

Even it's correct, it's not obvious, it's hard to imagine that future maintainers can know why it works.

Question 2: The error detection

The other expression is err.Error() != "signal: killed", so could the new expression be err.Error() != "context canceled" here? If not, what's the reason.

@wxiaoguang
Copy link
Contributor

ps: to clarify .... the questions above are not a blocker. Maybe only I have the difficulty to understand the logic ....

If someone can confirm it's correct, just give the approval (and I would really appreciate if someone could help explain the logic and questions .... 🙏)

@zeripath
Copy link
Contributor Author

zeripath commented Mar 6, 2022

Yes they are all correct.

Read the docs for context err. Different errs can be returned from the context err. If a context is cancelled due to its parent being cancelled it will have the same error.

It doesn't matter what caused the context to be cancelled it is cancelled.

The signal killed error also needs to be ignored due to cmd.Wait sometimes returning that when the exec is killed by the context being out of date.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 7, 2022

If it is the case, I think we should patch RunContext

if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded {
return err
}
return ctx.Err()

	if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded { 
		return err 
	} 
	if ctx.Err() == context.Canceled {
		// if the command (context) is canceled by our code, we shouldn't treat such result as an error
		return nil
	}
	return ctx.Err()

Or

We just check err != context.Canceled (errors.Is) in this PR (instead of ctx.Err() != err)


In this PR, if we use ctx.Err()!=err, then DeadlineExceeded would never be reported as error anymore (case 3 in the previous comment), but it seems to be better to report it, because the process might have been hanging for a while, there could be a bug or something wrong.

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

IMO err != context.Canceled could be more clear and correct, and we should report DeadlineExceeded as error.

If you are sure that c.ctx.Err() != err is by purpose, the comment could be updated to We should not pass up error due to the context being cancelled or it exceeds deadline

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 8, 2022
as per wxiaoguang

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@zeripath zeripath merged commit 8ddb549 into go-gitea:main Mar 8, 2022
@zeripath zeripath deleted the fix-18997-dont-report-ctx-closed-errors branch March 8, 2022 08:30
zeripath added a commit to zeripath/gitea that referenced this pull request Mar 8, 2022
Backport go-gitea#19006

Fix go-gitea#18997

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@zeripath zeripath added the backport/done All backports for this PR have been created label Mar 8, 2022
lunny pushed a commit that referenced this pull request Mar 8, 2022
)

Backport #19006

Fix #18997

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 9, 2022
* giteaofficial/main:
  Add button for issue deletion (go-gitea#19032)
  Fix script compatiable with OpenWrt (go-gitea#19000)
  Allow users to self-request a PR review (go-gitea#19030)
  Fix wrong scopes caused by empty scope input (go-gitea#19029)
  Feature: show issue assignee on project board (go-gitea#15232)
  bump go deps (go-gitea#19021)
  Don't show context cancelled errors in attribute reader (go-gitea#19006)
  Set `rel="nofollow noindex"` on new issue links (go-gitea#19023)
  update to correct stable version
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
Fix go-gitea#18997

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error on open last repository commit: "Unable to open checker for ..."
5 participants