limiter icon indicating copy to clipboard operation
limiter copied to clipboard

limiter kills previous goroutines if used 2 or more the same time

Open evgenyrelap opened this issue 3 years ago • 7 comments

type Workers struct {
	Scanner *limiter.ConcurrencyLimiter
	Reader  *limiter.ConcurrencyLimiter
	Remover *limiter.ConcurrencyLimiter
	Storage sync.Map
}

worker.Scanner.Execute(func() {
	err := readDir(path+"/"+e.Name(), worker, threadId, false)
	if err != nil {
		fmt.Println(err)
	}
})

worker.Reader stopping worker.Scanner once started.

worker.Reader.Execute(func() {
	for {
		data, ok := worker.Storage.Load(threadId)
		if ok {
			fmt.Println("buffer", threadId, "contains", len(data.([]int)), "elements")
			fmt.Println("scanner threads in progress", worker.Scanner.GetNumInProgress())
			fmt.Println("reader threads in progress", worker.Reader.GetNumInProgress())
		} else {
			fmt.Println("buffer", threadId, "is empty")
		}
		time.Sleep(time.Second * 5)
	}
})

evgenyrelap avatar Apr 06 '23 17:04 evgenyrelap

does it panic ? since if it does, the go routine will crash the process i believe.

korovkin avatar Apr 06 '23 18:04 korovkin

otherwise, i am not sure i understand the question

korovkin avatar Apr 06 '23 18:04 korovkin

No panic, no errors, new go routines of the first limiter does not spawn

Отправлено из мобильной Почты Mail.ru

четверг, 6 апреля 2023 г. в 21:26 +0300 от @.*** @.***>:

does it panic ? since if it does, the go routine will crash the process i believe. — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread. Message ID: <korovkin/limiter/issues/24/1499456607 @ github . com>

evgenyrelap avatar Apr 06 '23 18:04 evgenyrelap

I believe it just stops to spawn when the second one runs and working I’ve seen in in logs 

Отправлено из мобильной Почты Mail.ru

четверг, 6 апреля 2023 г. в 21:26 +0300 от @.*** @.***>:

otherwise, i am not sure i understand the question — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread. Message ID: <korovkin/limiter/issues/24/1499457131 @ github . com>

evgenyrelap avatar Apr 06 '23 18:04 evgenyrelap

perhaps you could share the whole end2end example with the main function so i could run it and understand it more ?

korovkin avatar Apr 06 '23 22:04 korovkin

`func main() { l1 := *limiter.NewConcurrencyLimiter(10) l2 := *limiter.NewConcurrencyLimiter(10)

l1.Execute(func() {
	for {
		fmt.Println("l1 is alive")
		time.Sleep(time.Second * 5)

		l2.Execute(func() {
			for {
				fmt.Println("l2 is alive")
				time.Sleep(time.Second * 5)
			}
		})
	}
})

l1.WaitAndClose()
l2.WaitAndClose()

}`

Run it and wait some time, you will see only l2 is alive after some minutes

evgenyrelap avatar Apr 07 '23 09:04 evgenyrelap

@evgenyrelap i tried the code above, it's running here -

it seems to work https://github.com/korovkin/limiter/pull/25

so what is the question

the usage pattern is not exactly as intended ... but still works, i believe.

korovkin avatar Apr 07 '23 19:04 korovkin