src/pkg/netchan/export.go | 5 ++++- diff --git a/src/pkg/netchan/export.go b/src/pkg/netchan/export.go index 318b865b0b9eb982747dc48e1796ec027ecd25f2..8c87ee8ce4cf3ae2931c78c67f4cbe4d1061bc91 100644 --- a/src/pkg/netchan/export.go +++ b/src/pkg/netchan/export.go @@ -52,6 +52,7 @@ mu sync.Mutex // protects remaining fields errored bool // client has been sent an error seqNum int64 // sequences messages sent to client; has value of highest sent ackNum int64 // highest sequence number acknowledged + seqLock sync.Mutex // guarantees messages are in sequence, only locked under mu } func newClient(exp *Exporter, conn net.Conn) *expClient { @@ -171,8 +172,10 @@ // number, not one beyond. client.mu.Lock() client.seqNum++ hdr.seqNum = client.seqNum - err := client.encode(&hdr, payData, val.Interface()) + client.seqLock.Lock() // guarantee ordering of messages client.mu.Unlock() + err := client.encode(&hdr, payData, val.Interface()) + client.seqLock.Unlock() if err != nil { expLog("error encoding client response:", err) client.sendError(&hdr, err.String())