Why does closing a channel in defer statement panics? : In the following example, a go routine is pumping values into unbuffered channel and the main function is iterating over it.

```go
package main

import (
	"fmt"
	"strconv"
)

var chanStr chan string

func main() {
	go pump()
	fmt.Println("iterating ...")
	for val := range chanStr {
		fmt.Printf("fetched val: %s from channel\n", val)
	}
}

func pump() {
	defer close(chanStr)
	chanStr = make(chan string)
	for i := 1; i <= 5; i++ {
		fmt.Printf("pumping seq %d into channel\n", i)
		chanStr <- "val" + strconv.Itoa(i)
	}
	//close(chanStr)
}
```

The function panics with the following output:

```
iterating ...                                             
pumping seq 1 into channel                                
pumping seq 2 into channel                                
fetched val: val1 from channel                            

......

fetched val: val4 from channel                            
pumping seq 5 into channel                                
panic: close of nil channel                               
                                                          
goroutine 5 [running]:                                    
main.pump()                                               
        C:/personal/gospace/go-rules/test.go:26 +0x1a6    
created by main.main                                      
        C:/personal/gospace/go-rules/test.go:11 +0x4e     
```

However if I comment the defer statement and close right after the for loop in the goroutine `pump` , the receiver doesn't panic. 
*What's the difference in both the cases?* Looks like defer closes the channel before the value is received but the regular close waits.

Also when I built using the race detector on, even in the regular close it flags a potential race condition (I'm not able recreate the race every time). Does it imply that both of those ways are not right in gracefully closing the channel?


