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

Conversation

@gnawux
Copy link
Member

@gnawux gnawux commented Apr 9, 2017

@gnawux
Copy link
Member Author

gnawux commented Apr 9, 2017

however, I am not sure should I consider the chan might block at some case.

h.Log(TRACE, "delay version-awared command :%d", cmd.Code)
time.AfterFunc(2*time.Millisecond, func() {
h.RLock()
defer h.RUnlock()
Copy link
Contributor

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

Copy link
Member Author

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....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok...

Copy link
Contributor

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()

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

h.RLock()
defer h.RUnlock()
if h.closed {
return
Copy link
Contributor

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

Copy link
Member Author

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.

@laijs
Copy link
Contributor

laijs commented Apr 10, 2017

however, I am not sure should I consider the chan might block at some case.

it is a possible, and cause deadlock.
it seems defer + recovery() proper.

@gnawux
Copy link
Member Author

gnawux commented Apr 10, 2017

�I don't like the taste of recover().... ok, it's a rare case....

@laijs
Copy link
Contributor

laijs commented Apr 10, 2017

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
        }
 }

@gnawux
Copy link
Member Author

gnawux commented Apr 10, 2017

@laijs I think you could close this and push a new PR

@gnawux
Copy link
Member Author

gnawux commented Apr 10, 2017

@laijs updated

@gnawux
Copy link
Member Author

gnawux commented Apr 10, 2017

I am considering should I use recover to avoid a lock in a hot path

h.ctlChan <- &hyperstartCmd{Code: res.Code, retMsg: res.Message}

@laijs
Copy link
Contributor

laijs commented Apr 10, 2017

it seams better to avoid the lock in handleMsgFromHyperstart()

@gnawux
Copy link
Member Author

gnawux commented Apr 10, 2017

ok, same idea. I will use the ugly recover instead.

@gnawux
Copy link
Member Author

gnawux commented Apr 10, 2017

updated again, with recover instead of lock

@laijs laijs merged commit b2fc393 into hyperhq:master Apr 11, 2017
gnawux added a commit to gnawux/hyper that referenced this pull request Apr 12, 2017
include: hyperhq/runv#469 hyperhq/runv#480 hyperhq/runv#482 hyperhq/runv#484
Signed-off-by: Wang Xu <gnawux@gmail.com>
jimoosciuc pushed a commit to jimoosciuc/runv that referenced this pull request May 26, 2020
check close before send delay command to hyperstart chan
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants