Golang Channel Deadlock

divshekhar profile image Divyanshu Shekhar Updated on ・1 min read

Golang Channel Deadlock

The number of channels is limited and whenever we try to receive or send value from and to the channel out of number, a deadlock occurs.

1. Receiving channels more than expected

    go func(ch <-chan int) {
        i := <-ch
        j := <-ch
        fmt.Println("Value of Channel i,j =", i, j)

Error:- fatal error: all goroutines are asleep – deadlock!

Here, there is only a single channel from where data is sent, and two receiving channels and thus Deadlock occurs.

Read Full Post on Golang Channel Deadlock.


Editor guide