<p dir="auto">by <strong><a href="mailto:dimitrij.denissenko@blacksquaremedia.com">dimitrij.denissenko@blacksquaremedia.com</a></strong>:</p>
<pre class="notranslate">What does 'go version' print?

go version go1.2 linux/amd64

What happened?

In my http server, I am trying to read the http.Request.Body via
ioutil.ReadAll(req.Body). Rarely, it causes an unexpected panic:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x5e65ca]
goroutine 1918503 [running]:
runtime.panic(0x7c3560, 0xd59d88)
  /home/user/.gvm/gos/go1.2/src/pkg/runtime/panic.c:266 +0xb6
io/ioutil.func·001()
  /home/user/.gvm/gos/go1.2/src/pkg/io/ioutil/ioutil.go:29 +0xf0
runtime.panic(0x7c3560, 0xd59d88)
  /home/user/.gvm/gos/go1.2/src/pkg/runtime/panic.c:248 +0x106
bufio.(*Reader).fill(0xc2101b1c00)
  /home/user/.gvm/gos/go1.2/src/pkg/bufio/bufio.go:91 +0x10a
bufio.(*Reader).Read(0xc2101b1c00, 0xc2119bde00, 0x1e5, 0x200, 0x1e5, ...)
  /home/user/.gvm/gos/go1.2/src/pkg/bufio/bufio.go:159 +0x1a4
io.(*LimitedReader).Read(0xc2107532e0, 0xc2119bde00, 0x200, 0x200, 0xc2119bde00, ...)
  /home/user/.gvm/gos/go1.2/src/pkg/io/io.go:398 +0xbb
net/http.(*body).Read(0xc2109ee4e0, 0xc2119bde00, 0x200, 0x200, 0x1, ...)
  /home/user/.gvm/gos/go1.2/src/pkg/net/http/transfer.go:534 +0x96
bytes.(*Buffer).ReadFrom(0xc21344b1c0, 0x7fe124670ee0, 0xc2109ee4e0, 0x0, 0x0, ...)
  /home/user/.gvm/gos/go1.2/src/pkg/bytes/buffer.go:169 +0x1f7
io/ioutil.readAll(0x7fe124670ee0, 0xc2109ee4e0, 0x200, 0x0, 0x0, ...)
  /home/user/.gvm/gos/go1.2/src/pkg/io/ioutil/ioutil.go:32 +0x156
io/ioutil.ReadAll(0x7fe124670ee0, 0xc2109ee4e0, 0x5320e1b2, 0x2a5129fd, 0x48349e, ...)
  /home/user/.gvm/gos/go1.2/src/pkg/io/ioutil/ioutil.go:41 +0x3f

What should have happened instead?

The documentation <a href="http://golang.org/src/pkg/net/http/request.go?#L114" rel="nofollow">http://golang.org/src/pkg/net/http/request.go?#L114</a> suggests that a
server body must never be nil.</pre>
<p dir="auto">by <strong>laf163</strong>:</p>
<pre class="notranslate">What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1.
func loginHandler(w http.ResponseWriter, r *http.Request) {
    ...
    cookie := http.Cookie{Name: "username", Value: "测试", Path: "/"}
    http.SetCookie(w, &amp;cookie)
    http.Redirect(w, r, path, http.StatusFound)
}
2.
func getScoreHandler(w http.ResponseWriter, r *http.Request) {
    username, err := r.Cookie("username")
    if err != nil {
        log.Printf("getScoreHandler: username=%s, err=%s", username, err)
        fmt.Fprintf(w, "%s", err)
        return
    }
    fmt.Fprint(w, "ok")
    ...
}

What is the expected output?
ok

What do you see instead?
http: named cookie not present

Which compiler are you using (5g, 6g, 8g, gccgo)?
go1.0.3.windows-386.msi 

Which operating system are you using?
win7 x64 home sp1

Which version are you using?  (run 'go version')
1.0.3

Please provide any additional information below.
if the value of username is english, there is no problem, if the value is chinese
string, read cookie will fail.</pre>