schollz / peerdiscovery

Pure-Go library for cross-platform local peer discovery using UDP multicast :woman: :repeat: :woman:
MIT License
638 stars 55 forks source link

Discovery hangs if executed in a loop #5

Closed jainpiyush19 closed 5 years ago

jainpiyush19 commented 5 years ago

I tried executing peerdiscovery.Discover() function in a loop and it stucks randomly after some time. After a little debugging, my hunch is, this is due to connection not being closed in listen() function. Please let me know if this is the actual reason or it is because of something else.

schollz commented 5 years ago

@piyushzomato Could you post an example that I could run that reproduces the bug?

jainpiyush19 commented 5 years ago

Please find below the sample code.

func test() {
    ticker := time.NewTicker(time.Second * 5)

    for {
        select {
        case <-ticker.C:
            discoveries, _ := peerdiscovery.Discover(peerdiscovery.Settings{
                Limit:     10,
                TimeLimit: time.Second * 4,
                Delay:     time.Second * 2,
                AllowSelf: false,
            })

            fmt.Println("Discovered Devices")
            for _, d := range discoveries {
                fmt.Println("Device : ", d)
            }
        }
    }
}
schollz commented 5 years ago

@piyushzomato Its running fine for me, 7+ minutes

jainpiyush19 commented 5 years ago

It happens randomly. Try running it multiple times.

schollz commented 5 years ago

@piyushzomato How many times? How many iterations does it go until it fails?