Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 05c709c

Browse files
authored
Merge pull request #485 from laijs/delay
delay version awared commands in hyperstartCommandWithRetMsg()
2 parents ffa17e8 + f012547 commit 05c709c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

hyperstart/libhyperstart/json.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ func handleCtlSock(h *jsonBasedHyperstart, ctlSock string, waitReady bool) error
193193
}
194194

195195
func (h *jsonBasedHyperstart) hyperstartCommandWithRetMsg(code uint32, msg interface{}) (retMsg []byte, err error) {
196+
if h.vmAPIVersion == 0 && (code == hyperstartapi.INIT_EXECCMD || code == hyperstartapi.INIT_NEWCONTAINER) {
197+
// delay version-awared command
198+
var t int64 = 2
199+
for h.vmAPIVersion == 0 {
200+
h.Log(TRACE, "delay version-awared command :%d by %dms", code)
201+
time.Sleep(time.Duration(t) * time.Millisecond)
202+
if t < 512 {
203+
t = t * 2
204+
}
205+
}
206+
}
207+
196208
defer func() {
197209
if recover() != nil {
198210
err = fmt.Errorf("send ctl channel error, the hyperstart might have closed")
@@ -258,19 +270,6 @@ func handleMsgToHyperstart(h *jsonBasedHyperstart, conn io.WriteCloser) {
258270
got = 0
259271
}
260272
} else {
261-
if h.vmAPIVersion == 0 && (cmd.Code == hyperstartapi.INIT_EXECCMD || cmd.Code == hyperstartapi.INIT_NEWCONTAINER) {
262-
// delay version-awared command
263-
h.Log(TRACE, "delay version-awared command :%d", cmd.Code)
264-
time.AfterFunc(2*time.Millisecond, func() {
265-
defer func() {
266-
if err := recover(); err != nil && h.closed {
267-
cmd.result <- fmt.Errorf("hyperstart closed")
268-
}
269-
}()
270-
h.ctlChan <- cmd
271-
})
272-
continue
273-
}
274273
var message []byte
275274
if message1, ok := cmd.Message.([]byte); ok {
276275
message = message1

0 commit comments

Comments
 (0)