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

Error: close of closed channel #118

Open
xeonds opened this issue Oct 10, 2024 · 0 comments
Open

Error: close of closed channel #118

xeonds opened this issue Oct 10, 2024 · 0 comments

Comments

@xeonds
Copy link

xeonds commented Oct 10, 2024

Occurrence: always, when the procedure has run after some time.

Error Message:

goroutine 462 [running]:                                                                                                                                                                                             
github.com/grandcat/zeroconf.(*LookupParams).done(...)                                                                                                                                                               
        /home/xeonds/go/pkg/mod/github.com/grandcat/[email protected]/service.go:84                                                                                                                                    
github.com/grandcat/zeroconf.(*client).mainloop(0xc0003143f0, {0xcba7d0, 0xc000f91090}, 0xc00028e380)                                                                                                                
        /home/xeonds/go/pkg/mod/github.com/grandcat/[email protected]/client.go:199 +0x4d0                                                                                                                             
created by github.com/grandcat/zeroconf.(*Resolver).Browse in goroutine 9                                                                                                                                            
        /home/xeonds/go/pkg/mod/github.com/grandcat/[email protected]/client.go:92 +0x251                                                                                                                              

Code:

func main(){
    go ScanDevice(5, db)
    select {}
}

func ScanDevices(duration int, db *gorm.DB) {
	resolver, err := zeroconf.NewResolver(nil)
	if err != nil {
		log.Fatalf("Failed to initialize mDNS resolver: %v", err)
	}
	entries := make(chan *zeroconf.ServiceEntry)

	go func(results <-chan *zeroconf.ServiceEntry) {
		for entry := range results {
			// some actions
		}
	}(entries)

	ctx := context.Background()

	for {
		err = resolver.Browse(ctx, "_iot-device._tcp", "local.", entries)
		if err != nil {
			log.Printf("Failed to browse mDNS: %v", err)
		}
		time.Sleep(time.Duration(duration) * time.Second)
	}
}
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

1 participant