From d6587be7bcacf7cdc5a547f8a2f3862b3d7bd8df Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 21 Mar 2017 22:05:53 +0400 Subject: [PATCH 1/3] [WSClient] allow for multiple restarts needed for https://github.com/tendermint/tools/pull/13/commits/3044f66ba90694927fb22ea5267de2a90bb3281b See https://github.com/tendermint/tools/issues/6 --- client/ws_client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/ws_client.go b/client/ws_client.go index b56547dd6..99737ca8f 100644 --- a/client/ws_client.go +++ b/client/ws_client.go @@ -53,6 +53,9 @@ func (wsc *WSClient) OnStart() error { if err != nil { return err } + + wsc.ResultsCh = make(chan json.RawMessage, wsResultsChannelCapacity) + wsc.ErrorsCh = make(chan error, wsErrorsChannelCapacity) go wsc.receiveEventsRoutine() return nil } From b0d2032488a16ce1497edd47e7c2e0dda246723f Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 28 Mar 2017 14:01:22 +0400 Subject: [PATCH 2/3] use BaseService.OnReset method to recreate channels --- client/ws_client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/ws_client.go b/client/ws_client.go index 99737ca8f..fb359bdaf 100644 --- a/client/ws_client.go +++ b/client/ws_client.go @@ -47,16 +47,21 @@ func (wsc *WSClient) String() string { return wsc.Address + ", " + wsc.Endpoint } +// OnStart implements cmn.BaseService interface func (wsc *WSClient) OnStart() error { wsc.BaseService.OnStart() err := wsc.dial() if err != nil { return err } + go wsc.receiveEventsRoutine() + return nil +} +// OnReset implements cmn.BaseService interface +func (wsc *WSClient) OnReset() error { wsc.ResultsCh = make(chan json.RawMessage, wsResultsChannelCapacity) wsc.ErrorsCh = make(chan error, wsErrorsChannelCapacity) - go wsc.receiveEventsRoutine() return nil } @@ -86,6 +91,7 @@ func (wsc *WSClient) dial() error { return nil } +// OnStop implements cmn.BaseService interface func (wsc *WSClient) OnStop() { wsc.BaseService.OnStop() // ResultsCh/ErrorsCh is closed in receiveEventsRoutine. From ba5382b70e65f89cd771157fc900cfc6adb22819 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 28 Mar 2017 14:17:40 +0400 Subject: [PATCH 3/3] open result&error channels on start --- client/ws_client.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/client/ws_client.go b/client/ws_client.go index fb359bdaf..8fa6189d1 100644 --- a/client/ws_client.go +++ b/client/ws_client.go @@ -32,12 +32,10 @@ type WSClient struct { func NewWSClient(remoteAddr, endpoint string) *WSClient { addr, dialer := makeHTTPDialer(remoteAddr) wsClient := &WSClient{ - Address: addr, - Dialer: dialer, - Endpoint: endpoint, - Conn: nil, - ResultsCh: make(chan json.RawMessage, wsResultsChannelCapacity), - ErrorsCh: make(chan error, wsErrorsChannelCapacity), + Address: addr, + Dialer: dialer, + Endpoint: endpoint, + Conn: nil, } wsClient.BaseService = *cmn.NewBaseService(log, "WSClient", wsClient) return wsClient @@ -54,14 +52,14 @@ func (wsc *WSClient) OnStart() error { if err != nil { return err } + wsc.ResultsCh = make(chan json.RawMessage, wsResultsChannelCapacity) + wsc.ErrorsCh = make(chan error, wsErrorsChannelCapacity) go wsc.receiveEventsRoutine() return nil } // OnReset implements cmn.BaseService interface func (wsc *WSClient) OnReset() error { - wsc.ResultsCh = make(chan json.RawMessage, wsResultsChannelCapacity) - wsc.ErrorsCh = make(chan error, wsErrorsChannelCapacity) return nil }