larsth / go9p

Automatically exported from code.google.com/p/go9p
Other
0 stars 0 forks source link

doesn't handle connection close #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Start a server (I tried with examples ufs.go)

2. Start client which reads a (big) file, like

    file, err := c.FOpen(name, p.OREAD)
  if err != nil {
        return nil, os.NewError(err.String())
  }
    defer file.Close()

    buf := make([]byte, 8192)
  for {
        fmt.Printf("reading chunk\n")
    n, err := file.Read(buf)
    if err != nil {
            return nil, os.NewError(err.String())
    }

    if n == 0 {
        break
    }

        dest.Write(buf[0:n])
  }

3. Kill the server in the middle of the write

The reader will be stuck during read and never resume.

Original issue reported on code.google.com by mmikuli...@gmail.com on 31 May 2011 at 1:32

GoogleCodeExporter commented 9 years ago
After some debugging I found out that the file.Read call returns correcty an 
EOF error, but my client doesn't return because it's blocked on "defer 
file.Close()".

I believe it's a bug and that file.Close() should be able to complete also in 
this circumstance.

Original comment by mmikuli...@gmail.com on 31 May 2011 at 2:21

GoogleCodeExporter commented 9 years ago
So basically what happens is that after a connection is broken every next 
attempt to send rpc messages will block.

This happens because the "Send" goroutine exits without closing his acceptor 
channel:

func (clnt *Clnt) send() {
    for {
        select {
        case <-clnt.done:
            return
...

Attaching a patch.

Original comment by mmikuli...@gmail.com on 31 May 2011 at 3:07

GoogleCodeExporter commented 9 years ago

Original comment by mmikuli...@gmail.com on 31 May 2011 at 3:08

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for catching this.

I think there is much simpler fix, just pushed it. Can you please check if it 
fixes the bug for you?

Thanks,
    Lucho

Original comment by lion...@gmail.com on 31 May 2011 at 7:56