-
Notifications
You must be signed in to change notification settings - Fork 128
check close before send delay command to hyperstart chan #482
Conversation
|
however, I am not sure should I consider the chan might block at some case. |
hyperstart/libhyperstart/json.go
Outdated
| h.Log(TRACE, "delay version-awared command :%d", cmd.Code) | ||
| time.AfterFunc(2*time.Millisecond, func() { | ||
| h.RLock() | ||
| defer h.RUnlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer is called when the exit of the function, not when the exit of the scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an anonymous func....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seams the lock is also needed in the handleMsgFromHyperstart()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h.ctlChan <- &hyperstartCmd{Code: res.Code, retMsg: res.Message}
this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
hyperstart/libhyperstart/json.go
Outdated
| h.RLock() | ||
| defer h.RUnlock() | ||
| if h.closed { | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an error is needed to be sent to cmd.result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks so, will add it.
it is a possible, and cause deadlock. |
|
�I don't like the taste of |
|
one of the ways to avoid the deadlock, but I don't like it either. diff --git a/hyperstart/libhyperstart/json.go b/hyperstart/libhyperstart/json.go
index 852a690..76ffbf0 100644
--- a/hyperstart/libhyperstart/json.go
+++ b/hyperstart/libhyperstart/json.go
@@ -82,6 +82,13 @@ func (h *jsonBasedHyperstart) Log(level hlog.LogLevel, args ...interface{}) {
}
func (h *jsonBasedHyperstart) Close() {
+ go func() {
+ for cmd := range h.ctlChan {
+ if cmd.Code != hyperstartapi.INIT_ACK && cmd.Code != hyperstartapi.INIT_ERROR {
+ cmd.result <- fmt.Errorf("hyperstart closed")
+ }
+ }
+ }()
h.Lock()
defer h.Unlock()
if !h.closed {
@@ -97,11 +104,6 @@ func (h *jsonBasedHyperstart) Close() {
close(h.ctlChan)
close(h.streamChan)
close(h.processAsyncEvents)
- for cmd := range h.ctlChan {
- if cmd.Code != hyperstartapi.INIT_ACK && cmd.Code != hyperstartapi.INIT_ERROR {
- cmd.result <- fmt.Errorf("hyperstart closed")
- }
- }
h.closed = true
}
} |
|
@laijs I think you could close this and push a new PR |
|
@laijs updated |
|
I am considering should I use recover to avoid a lock in a hot path |
|
it seams better to avoid the lock in handleMsgFromHyperstart() |
|
ok, same idea. I will use the ugly recover instead. |
|
updated again, with recover instead of lock |
see http://ci.hypercontainer.io:8080/job/hyperd-auto/330/consoleFull Signed-off-by: Wang Xu <gnawux@gmail.com>
include: hyperhq/runv#469 hyperhq/runv#480 hyperhq/runv#482 hyperhq/runv#484 Signed-off-by: Wang Xu <gnawux@gmail.com>
check close before send delay command to hyperstart chan
see http://ci.hypercontainer.io:8080/job/hyperd-auto/330/consoleFull
Signed-off-by: Wang Xu gnawux@gmail.com