Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect silent network drops. #320

Closed
wants to merge 4 commits into from
Closed

Conversation

jrick
Copy link
Member

@jrick jrick commented Sep 16, 2015

This change introduces additional network activity with the btcd
process to ensure that the network connection is not silently dropped.
Previously, if the connection was lost (e.g. wallet runs on a laptop
and connects to remote btcd, and the laptop is suspended/resumed) the
lost connection would not be detectable since all normal RPC activity
(excluding requests from btcwallet to btcd made by the user) is in the
direction of btcd to wallet in the form of websocket notifications.

Rather than simply pinging the server and waiting for the response, a
unique session ID has been added for each websocket client connection.
These session IDs are randomly generated by the btcd RPC server when a
new websocket connection is established, and are queried using the
session RPC. If the session ID changes, it is assumed that the
connection silently reconnected, and the client is shutdown for this
case as well.

Requires btcsuite/btcd#500 and btcsuite/btcrpcclient#62

This change introduces additional network activity with the btcd
process to ensure that the network connection is not silently dropped.
Previously, if the connection was lost (e.g. wallet runs on a laptop
and connects to remote btcd, and the laptop is suspended/resumed) the
lost connection would not be detectable since all normal RPC activity
(excluding requests from btcwallet to btcd made by the user) is in the
direction of btcd to wallet in the form of websocket notifications.

Rather than simply pinging the server and waiting for the response, a
unique session ID has been added for each websocket client connection.
These session IDs are randomly generated by the btcd RPC server when a
new websocket connection is established, and are queried using the
session RPC.  If the session ID changes, it is assumed that the
connection silently reconnected, and the client is shutdown for this
case as well.
@davecgh
Copy link
Member

davecgh commented Sep 17, 2015

This appears to be resetting back to height 0 after a disconnect:

12:14:44 2015-09-17 [INF] WLLT: Started rescan from block 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943 (height 0) for 1 address
...
12:20:34 2015-09-17 [INF] WLLT: Finished rescan for 1 address (synced to block 0000000003c34aa56f526562497c63e9cedc59dbac76c385efdd0cdbee6e3419, height 556333)
...
_Killed remote connection here_
12:27:19 2015-09-17 [ERR] CHNS: Failed to receive session result: <nil>
12:27:19 2015-09-17 [INF] CHNS: Established websocket RPC connection to btcd
12:27:19 2015-09-17 [INF] WLLT: Started rescan from block 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943 (height 0) for 1 address

@davecgh
Copy link
Member

davecgh commented Sep 17, 2015

It appears working properly now with the latest commit:

14:13:17 2015-09-17 [INF] WLLT: Finished rescan for 1 address (synced to block 0000000000025723097205ec8ae22750fec0e6fabb1eee027a61a19d5b1c2f63, height 556361)
...
_Killed remote connection here_
14:14:17 2015-09-17 [ERR] CHNS: Failed to receive session result: the client has been shutdown
14:14:17 2015-09-17 [INF] CHNS: Established websocket RPC connection to btcd
14:14:17 2015-09-17 [INF] WLLT: Started rescan from block 0000000000025723097205ec8ae22750fec0e6fabb1eee027a61a19d5b1c2f63 (height 556361) for 1 address
14:14:17 2015-09-17 [INF] WLLT: Finished rescan for 1 address (synced to block 0000000000025723097205ec8ae22750fec0e6fabb1eee027a61a19d5b1c2f63, height 556361)

Session ID doesn't have to be checked since we control the
btcrpcclient reconnect logic by disabling it.
@davecgh
Copy link
Member

davecgh commented Sep 22, 2015

OK (after squash and rebase to master)

@jrick
Copy link
Member Author

jrick commented Sep 22, 2015

squashed+merged as 33d053c

@jrick jrick closed this Sep 22, 2015
@jrick jrick deleted the jrick_session branch September 22, 2015 18:51
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.

2 participants