From d8913a63549b25fdf4cce7a5d511ab651140eec6 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 22 Apr 2014 04:01:51 +0800 Subject: [PATCH] fix race --- worker/agent.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/worker/agent.go b/worker/agent.go index 2236173..074af00 100644 --- a/worker/agent.go +++ b/worker/agent.go @@ -137,10 +137,14 @@ func (a *agent) read(length int) (data []byte, err error) { return } +var m = sync.Mutex{} + // Internal write the encoded job. func (a *agent) write(outpack *outPack) (err error) { var n int buf := outpack.Encode() + m.Lock() + defer m.Unlock() for i := 0; i < len(buf); i += n { n, err = a.rw.Write(buf[i:]) if err != nil {