This commit is contained in:
ngaut 2014-04-22 02:29:06 +00:00
commit df43075092
2 changed files with 5 additions and 0 deletions

View File

@ -137,10 +137,14 @@ func (a *agent) read(length int) (data []byte, err error) {
return return
} }
var m = sync.Mutex{}
// Internal write the encoded job. // Internal write the encoded job.
func (a *agent) write(outpack *outPack) (err error) { func (a *agent) write(outpack *outPack) (err error) {
var n int var n int
buf := outpack.Encode() buf := outpack.Encode()
m.Lock()
defer m.Unlock()
for i := 0; i < len(buf); i += n { for i := 0; i < len(buf); i += n {
n, err = a.rw.Write(buf[i:]) n, err = a.rw.Write(buf[i:])
if err != nil { if err != nil {

View File

@ -279,6 +279,7 @@ func (worker *Worker) exec(inpack *inPack) (err error) {
} }
outpack.handle = inpack.handle outpack.handle = inpack.handle
outpack.data = r.data outpack.data = r.data
//exec() maybe called concurrently, take care of race condition
inpack.a.write(outpack) inpack.a.write(outpack)
} }
return return