Skip to content

Commit

Permalink
fixed a bug whereby go 1.1 doesn't prevent against pipe write deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
imkira committed Nov 24, 2016
1 parent 2c4cb9d commit 85f0c79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func newSession(t *testing.T) (io.ReadWriteCloser, *server) {
rs, wc := io.Pipe()
rc, ws := io.Pipe()

rws := &logIO{t, "server", pipe{rs, ws}}
rwc := &logIO{t, "client", pipe{rc, wc}}
rws := &logIO{t, "server", &pipe{r: rs, w: ws}}
rwc := &logIO{t, "client", &pipe{r: rc, w: wc}}

server := server{
T: t,
Expand Down
21 changes: 18 additions & 3 deletions shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,38 @@ package amqp
import (
"encoding/hex"
"io"
"sync"
"testing"
)

type pipe struct {
r *io.PipeReader
w *io.PipeWriter

m sync.Mutex
closed bool
}

func (p pipe) Read(b []byte) (int, error) {
func (p *pipe) Read(b []byte) (int, error) {
return p.r.Read(b)
}

func (p pipe) Write(b []byte) (int, error) {
func (p *pipe) Write(b []byte) (int, error) {
p.m.Lock()
defer p.m.Unlock()
if p.closed {
return 0, io.ErrClosedPipe
}
return p.w.Write(b)
}

func (p pipe) Close() error {
func (p *pipe) Close() error {
p.m.Lock()
defer p.m.Unlock()
if p.closed {
return nil
}
p.closed = true
p.r.Close()
p.w.Close()
return nil
Expand Down

0 comments on commit 85f0c79

Please sign in to comment.