Merge pull request #293 from filecoin-project/fix/websocket-closing-2

fix websocket closing again
This commit is contained in:
Łukasz Magiera 2019-10-08 10:34:44 +02:00 committed by GitHub
commit 49e8b5d334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

View File

@ -88,6 +88,7 @@ func NewMergeClient(addr string, namespace string, outs []interface{}, requestHe
} }
stop := make(chan struct{}) stop := make(chan struct{})
exiting := make(chan struct{})
c.requests = make(chan clientRequest) c.requests = make(chan clientRequest)
handlers := map[string]rpcHandler{} handlers := map[string]rpcHandler{}
@ -96,6 +97,7 @@ func NewMergeClient(addr string, namespace string, outs []interface{}, requestHe
handler: handlers, handler: handlers,
requests: c.requests, requests: c.requests,
stop: stop, stop: stop,
exiting: exiting,
}).handleWsConn(context.TODO()) }).handleWsConn(context.TODO())
for _, handler := range outs { for _, handler := range outs {
@ -122,6 +124,7 @@ func NewMergeClient(addr string, namespace string, outs []interface{}, requestHe
return func() { return func() {
close(stop) close(stop)
<-exiting
}, nil }, nil
} }

View File

@ -52,6 +52,7 @@ func (s *RPCServer) handleWS(ctx context.Context, w http.ResponseWriter, r *http
(&wsConn{ (&wsConn{
conn: c, conn: c,
handler: s.methods, handler: s.methods,
exiting: make(chan struct{}),
}).handleWsConn(ctx) }).handleWsConn(ctx)
if err := c.Close(); err != nil { if err := c.Close(); err != nil {

View File

@ -43,6 +43,7 @@ type wsConn struct {
handler handlers handler handlers
requests <-chan clientRequest requests <-chan clientRequest
stop <-chan struct{} stop <-chan struct{}
exiting chan struct{}
// incoming messages // incoming messages
incoming chan io.Reader incoming chan io.Reader
@ -389,6 +390,7 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
c.registerCh = make(chan outChanReg) c.registerCh = make(chan outChanReg)
defer close(c.registerCh) defer close(c.registerCh)
defer close(c.exiting)
// //// // ////