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

'panic: close of closed channel' using simple example code #63

Closed
christophershirk opened this issue Apr 5, 2020 · 1 comment
Closed

Comments

@christophershirk
Copy link

What version of the package are you using?

v0.10.7

What are you trying to do?

Run example code

import (
        "net/http"
        "github.com/caddyserver/certmagic"
        "fmt"
        "log"

)


func main() {
        http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
                fmt.Fprintf(w, "Hello world")
        })

        err := certmagic.HTTPS([]string{"tmp.mydomain.com"}, nil)
        if err != nil {
                log.Fatal(err)
        }
}

What steps did you take?

  1. On tmp.mydomain.com server, removed .local/share/certmagic directory (to start fresh)
  2. Built code locally, scp'd to tmp.mydomain.com
  3. On tmp.mydomain.com, performed: setcap 'cap_net_bind_service=+ep' ./autotest3 && ./autotest3

What did you expect to happen, and what actually happened instead?

Sometimes the example code works, sometimes it panics like this:

2020/04/05 00:21:57 [INFO][tmp.mydomain.com] Obtain certificate; acquiring lock...
2020/04/05 00:21:57 [INFO][tmp.mydomain.com] Obtain: Lock acquired; proceeding...
2020/04/05 00:21:57 [INFO] acme: Registering account for dude@mydomain.com
2020/04/05 00:21:57 [INFO][tmp.mydomain.com] Waiting on rate limiter...
2020/04/05 00:21:57 [INFO][tmp.mydomain.com] Done waiting
2020/04/05 00:21:57 [INFO] [tmp.mydomain.com] acme: Obtaining bundled SAN certificate given a CSR
2020/04/05 00:21:57 [INFO] [tmp.mydomain.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz-v3/3765978543
2020/04/05 00:21:57 [INFO] [tmp.mydomain.com] acme: use tls-alpn-01 solver
2020/04/05 00:21:57 [INFO] [tmp.mydomain.com] acme: Trying to solve TLS-ALPN-01
2020/04/05 00:21:58 [INFO][tmp.mydomain.com] Served key authentication certificate (TLS-ALPN challenge)
2020/04/05 00:21:58 [INFO][tmp.mydomain.com] Served key authentication certificate (TLS-ALPN challenge)
2020/04/05 00:21:58 [INFO][tmp.mydomain.com] Served key authentication certificate (TLS-ALPN challenge)
2020/04/05 00:21:58 [INFO][tmp.mydomain.com] Served key authentication certificate (TLS-ALPN challenge)
2020/04/05 00:22:04 [INFO] [tmp.mydomain.com] The server validated our request
panic: close of closed channel
        panic: close of closed channel
        panic: close of closed channel
        panic: close of closed channel

goroutine 29 [running]:
github.com/caddyserver/certmagic.(*tlsALPNSolver).Present.func1(0xc0000f5da0, 0xc000326cc0)
        /home/x/go/pkg/mod/github.com/caddyserver/certmagic@v0.10.7/solvers.go:155 +0x177
created by github.com/caddyserver/certmagic.(*tlsALPNSolver).Present
        /home/x/go/pkg/mod/github.com/caddyserver/certmagic@v0.10.7/solvers.go:149 +0x709

How do you think this should be fixed?

Out of curiosity, I built the code both with the datarace detector enabled and disabled, and I can reproduce the issue (intermittently) in both cases.

@mholt
Copy link
Member

mholt commented Apr 5, 2020

Thanks for the report, but this is fixed already. 😃 Simply upgrade to the latest version.

@mholt mholt closed this as completed Apr 5, 2020
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

No branches or pull requests

2 participants