Use single decoder instance for one stream

This will avoid part of the stream be read and abandomed
and resulting decoding errors.

Signed-off-by: Hushan Jia <hushan.jia@gmail.com>
This commit is contained in:
Hushan Jia 2016-02-26 19:12:11 +08:00
parent 53e4dd65f5
commit 8597d5c969
1 changed files with 3 additions and 2 deletions

View File

@ -241,9 +241,10 @@ func (p *initProcess) start() (err error) {
ierr *genericError
)
dec := json.NewDecoder(p.parentPipe)
loop:
for {
if err := json.NewDecoder(p.parentPipe).Decode(&procSync); err != nil {
if err := dec.Decode(&procSync); err != nil {
if err == io.EOF {
break loop
}
@ -281,7 +282,7 @@ loop:
case procError:
// wait for the child process to fully complete and receive an error message
// if one was encoutered
if err := json.NewDecoder(p.parentPipe).Decode(&ierr); err != nil && err != io.EOF {
if err := dec.Decode(&ierr); err != nil && err != io.EOF {
return newSystemError(err)
}
if ierr != nil {