Skip to content

Error: close of closed channel #118

Open
@xeonds

Description

@xeonds

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)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions