Skip to content

rpc: subscribe on reconnection - #689

Merged
melekes merged 2 commits into
tendermint:unstablefrom
stratumn:fix-ws-reconnect
Sep 29, 2017
Merged

melekes merged 2 commits into
tendermint:unstablefrom
stratumn:fix-ws-reconnect

Conversation

@alexppxela

Copy link
Copy Markdown
Contributor

When connection is lost with server, client does not re-subscribe so client is not notified anymore.

@melekes
melekes changed the base branch from master to develop September 28, 2017 15:30
@melekes

melekes commented Sep 28, 2017

Copy link
Copy Markdown
Contributor

wow! thanks a lot

c.Logger.Error("failed to redial", "err", err)
} else {
c.Logger.Info("reconnected")
c.ReconnectCh <- true

@melekes melekes Sep 28, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer an optional callback here:

go c.OnReconnect()

this way user won't be forced to read from ReconnectCh (because if he isn't, a client would block now).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@melekes does this apply though since I believe that ReconnectCh was exported so that we could use it in rpc/client/httpclient.go at https://github.com/tendermint/tendermint/pull/689/files#diff-a969276db2d519208a2bf7aa9447acf6R338
screen shot 2017-09-29 at 1 21 50 am
as this file is in rpc/lib/client so we need that visibility to be able to use it there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're true, for me it is the best way to delegate reconnection behavior to WSEvents.
I've just fixed the unit tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@odeke-em yes, it is. you probably did not notice, but OnReconnect is also exported. so in httpclient we should be able to do:

w.ws.OnReconnect = func() {
  w.redoSubscriptions()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ooh I see, roger that @melekes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I rewrote some code here da5bd25. Feel free to leave your comments.

@codecov-io

codecov-io commented Sep 29, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #689 into unstable will decrease coverage by 0.25%.
The diff coverage is 28.57%.

@@             Coverage Diff              @@
##           unstable     #689      +/-   ##
============================================
- Coverage     56.59%   56.33%   -0.26%     
============================================
  Files            80       81       +1     
  Lines          8386     8408      +22     
============================================
- Hits           4746     4737       -9     
- Misses         3231     3265      +34     
+ Partials        409      406       -3

@melekes
melekes changed the base branch from develop to unstable September 29, 2017 09:31
@melekes
melekes merged commit c373978 into tendermint:unstable Sep 29, 2017
zramsay pushed a commit that referenced this pull request Oct 2, 2017
* rpc: subscribe on reconnection

* rpc: fix unit tests
firelizzard18 pushed a commit to AccumulateNetwork/tendermint that referenced this pull request Nov 24, 2023
…nt#689)

* Repro in e2e tests

* Change something in the code

* Fix race condition in `SwitchToConsensus`

* Revert "Repro in e2e tests"

This reverts commit 4f441f8ebac8f245d5a641c25ccdfa3b382ca063.

* RAII lock

(cherry picked from commit 6a96eca)

Co-authored-by: Sergio Mena <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants