title: Why does sending a value more than buffered channel size in Golang causes deadlock error?
body: <pre><code>// By default channels are _unbuffered_, meaning that they
  // will only accept sends (`chan &lt;-`) if there is a
  // corresponding receive (`&lt;- chan`) ready to receive the
  // sent value. _Buffered channels_ accept a limited
  // number of  values without a corresponding receiver for
  // those values.
  
  package main
  
  import "fmt"
  
  func main() {
  
      // Here we `make` a channel of strings buffering up to
      // 2 values.
      messages := make(chan string, 2)
  
      // Because this channel is buffered, we can send these
      // values into the channel without a corresponding
      // concurrent receive.
      messages &lt;- "buffered"
      messages &lt;- "channel"
      messages &lt;- "channel1" //I added this. 
  
      // Later we can receive these two values as usual.
      fmt.Println(&lt;-messages)
      fmt.Println(&lt;-messages)
  }
  </code></pre>
  
  <p>Error it throws:</p>
  
  <pre><code>fatal error: all goroutines are asleep - deadlock!
  
  goroutine 1 [chan send]:
  main.main()
      /tmp/sandbox795158698/prog.go:23 +0x8d
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>Can't we send more values than buffer size? </li>
  <li>Why the error says
  "all goroutines are asleep - deadlock!" when there are no goroutines
  here in the code? </li>
  <li>Why is it this a deadlock? Please explain?</li>
  </ol>
  
  <p><a href="https://play.golang.org/p/qFqFpJhEUV-" rel="nofollow noreferrer">PlayGroundLink</a></p>