goroutine collection mechanism

goroutine with the fork-join model

This model also is a kind of ideological divide and conquer

All goroutine fork will then join the collection sent out back

join in the process of collecting back using the channel

At the same time a join point may be synchronization of multiple goroutine

After fork out before returning to the current goroutine is no way to control the issue of goroutine

Although we can use context to limit overtime

However, since only the context related context goroutine of the reader and the user receiver recipient does not associate the sender

So if a user reading a timeout sender is no way to terminate the sender can only terminate itself

The reading of it leaked goroutine

So goroutine no good collection mechanism

The problem seems to only be solved by restarting

Increase a timeout is restarted several times less

 

reference:

https://stackoverflow.com/questions/50570961/stop-goroutine-execution-on-timeout?answertab=votes#tab-top

Guess you like

Origin www.cnblogs.com/general10/p/12033388.html