Skip to content

Commit

Permalink
Fix #317, Prevents premature closure of the channel in case of a time…
Browse files Browse the repository at this point in the history
…out that leads to a panic

1. Adjusting the timing of channel closures
2. Ensure that the channel is of sufficient size
  • Loading branch information
haoyu234 authored and felipejfc committed Sep 6, 2023
1 parent 8b39f93 commit de646f2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cluster/etcd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ func (sd *etcdServiceDiscovery) Shutdown() error {
// revoke prevents Pitaya from crashing when etcd is not available
func (sd *etcdServiceDiscovery) revoke() error {
close(sd.stopLeaseChan)
c := make(chan error)
defer close(c)
c := make(chan error, 1)
go func() {
defer close(c)
logger.Log.Debug("waiting for etcd revoke")
_, err := sd.cli.Revoke(context.TODO(), sd.leaseID)
c <- err
Expand Down

1 comment on commit de646f2

@bruce1125
Copy link
Contributor

Choose a reason for hiding this comment

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

To set an explicit capacity of channel could't solve the issue, because when executing the code [ c <- err ], the channel possibly had been closed, and it would cause a panic.
For me, now I just add a recover() in the waiting goroutine.

Please sign in to comment.