From f01254713735dba62e285dffd27246d9a1e4a8c3 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Wed, 12 Apr 2017 10:45:23 +0800 Subject: [PATCH] delay version awared commands in hyperstartCommandWithRetMsg() Signed-off-by: Lai Jiangshan --- hyperstart/libhyperstart/json.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hyperstart/libhyperstart/json.go b/hyperstart/libhyperstart/json.go index 389b1c6a..2e6bb579 100644 --- a/hyperstart/libhyperstart/json.go +++ b/hyperstart/libhyperstart/json.go @@ -193,6 +193,18 @@ func handleCtlSock(h *jsonBasedHyperstart, ctlSock string, waitReady bool) error } func (h *jsonBasedHyperstart) hyperstartCommandWithRetMsg(code uint32, msg interface{}) (retMsg []byte, err error) { + if h.vmAPIVersion == 0 && (code == hyperstartapi.INIT_EXECCMD || code == hyperstartapi.INIT_NEWCONTAINER) { + // delay version-awared command + var t int64 = 2 + for h.vmAPIVersion == 0 { + h.Log(TRACE, "delay version-awared command :%d by %dms", code) + time.Sleep(time.Duration(t) * time.Millisecond) + if t < 512 { + t = t * 2 + } + } + } + defer func() { if recover() != nil { err = fmt.Errorf("send ctl channel error, the hyperstart might have closed") @@ -258,19 +270,6 @@ func handleMsgToHyperstart(h *jsonBasedHyperstart, conn io.WriteCloser) { got = 0 } } else { - if h.vmAPIVersion == 0 && (cmd.Code == hyperstartapi.INIT_EXECCMD || cmd.Code == hyperstartapi.INIT_NEWCONTAINER) { - // delay version-awared command - h.Log(TRACE, "delay version-awared command :%d", cmd.Code) - time.AfterFunc(2*time.Millisecond, func() { - defer func() { - if err := recover(); err != nil && h.closed { - cmd.result <- fmt.Errorf("hyperstart closed") - } - }() - h.ctlChan <- cmd - }) - continue - } var message []byte if message1, ok := cmd.Message.([]byte); ok { message = message1