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

dkim: Always close done channel in Sign #15

Merged
merged 1 commit into from
Oct 28, 2019

Conversation

foxcpp
Copy link
Contributor

@foxcpp foxcpp commented Oct 27, 2019

Added defer close(done) as proposed in the linked issue.

Closes #8.

@codecov-io
Copy link

Codecov Report

Merging #15 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #15   +/-   ##
=======================================
  Coverage   66.46%   66.46%           
=======================================
  Files           7        7           
  Lines         832      832           
=======================================
  Hits          553      553           
  Misses        210      210           
  Partials       69       69
Impacted Files Coverage Δ
dkim/sign.go 66.88% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56e7fdd...af51aa1. Read the comment docs.

@emersion
Copy link
Owner

Not sure why this is necessary. closeReadWithError should make the pipe always return an error?

@foxcpp
Copy link
Contributor Author

foxcpp commented Oct 28, 2019

The problem is in dkim.Sign function, in case of signing error, it calls Close twice:

if err := s.Close(); err != nil {

and then also in defer:
defer s.Close()

Second Close reads from done and blocks forever. close(done) fixes it by closing channel so it will return null value without blocking after first read. This makes Close function idempotent (it is safe to call it multiple times), which is also a convenient thing to have.

@emersion
Copy link
Owner

Sure, but I don't get why s.pw.Close() doesn't return an error in this case?

@foxcpp
Copy link
Contributor Author

foxcpp commented Oct 28, 2019

Because it doesn't have to?
https://golang.org/pkg/io/#PipeWriter
Docs tell that only Write returns an error in case of CloseWithError on read end.

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Ah, I see. I guess it doesn't matter to return an error in our Close function, because our Write function would have returned an error before.

@emersion emersion merged commit ca59a51 into emersion:master Oct 28, 2019
@emersion
Copy link
Owner

Thanks!

@foxcpp foxcpp deleted the dkim-sign-hang branch October 28, 2019 23:01
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.

dkim.Sign blocks indefinitely on early errors
3 participants