Skip to content

Commit

Permalink
Prevent Check to send result to closed channel (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmdrs authored Oct 21, 2022
1 parent 16d80ba commit c509188
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ import (
"net/http"
"time"

"github.com/hellofresh/health-go/v4"
healthMysql "github.com/hellofresh/health-go/v4/checks/mysql"
"github.com/hellofresh/health-go/v5"
healthMysql "github.com/hellofresh/health-go/v5/checks/mysql"
)

func main() {
// add some checks on instance creation
h, _ := health.New(health.WithComponent(health.Component{
Name: "myservice",
Version: "v1.0",
}), health.WithChecks(health.Config{
Name: "myservice",
Version: "v1.0",
}), health.WithChecks(health.Config{
Name: "rabbitmq",
Timeout: time.Second * 5,
SkipOnErr: true,
Expand Down Expand Up @@ -82,16 +82,16 @@ import (
"time"

"github.com/go-chi/chi"
"github.com/hellofresh/health-go/v4"
healthMysql "github.com/hellofresh/health-go/v4/checks/mysql"
"github.com/hellofresh/health-go/v5"
healthMysql "github.com/hellofresh/health-go/v5/checks/mysql"
)

func main() {
// add some checks on instance creation
h, _ := health.New(health.WithComponent(health.Component{
Name: "myservice",
Version: "v1.0",
}), health.WithChecks(health.Config{
Name: "myservice",
Version: "v1.0",
}), health.WithChecks(health.Config{
Name: "rabbitmq",
Timeout: time.Second * 5,
SkipOnErr: true,
Expand Down
8 changes: 4 additions & 4 deletions _examples/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"net/http"
"time"

"github.com/hellofresh/health-go/v4"
healthHttp "github.com/hellofresh/health-go/v4/checks/http"
healthMySql "github.com/hellofresh/health-go/v4/checks/mysql"
healthPg "github.com/hellofresh/health-go/v4/checks/postgres"
"github.com/hellofresh/health-go/v5"
healthHttp "github.com/hellofresh/health-go/v5/checks/http"
healthMySql "github.com/hellofresh/health-go/v5/checks/mysql"
healthPg "github.com/hellofresh/health-go/v5/checks/postgres"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion checks/rabbitmq/aliveness_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/hellofresh/health-go/v4/checks/http"
"github.com/hellofresh/health-go/v5/checks/http"
)

const httpURLEnv = "HEALTH_GO_MQ_URL"
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"net/http"
"time"

"github.com/hellofresh/health-go/v4"
healthMysql "github.com/hellofresh/health-go/v4/checks/mysql"
"github.com/hellofresh/health-go/v5"
healthMysql "github.com/hellofresh/health-go/v5/checks/mysql"
)

func main() {
Expand Down Expand Up @@ -77,8 +77,8 @@ import (
"time"

"github.com/go-chi/chi"
"github.com/hellofresh/health-go/v4"
healthMysql "github.com/hellofresh/health-go/v4/checks/mysql"
"github.com/hellofresh/health-go/v5"
healthMysql "github.com/hellofresh/health-go/v5/checks/mysql"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/hellofresh/health-go/v4
module github.com/hellofresh/health-go/v5

go 1.18

Expand Down
12 changes: 2 additions & 10 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,10 @@ func (h *Health) Measure(ctx context.Context) Check {
}()

resCh := make(chan error)
defer close(resCh)

go func() {
res := c.Check(ctx)

select {
case <-resCh:
// channel is already closed
return
default:
resCh <- res
}
resCh <- c.Check(ctx)
defer close(resCh)
}()

select {
Expand Down

0 comments on commit c509188

Please sign in to comment.