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

Adds retry mechanism to reconnect for more robustness #454

Closed

Conversation

fusiondog
Copy link

@fusiondog fusiondog commented Nov 22, 2016

Not too fancy but implements a retry mechanism that falls back in frequency and eventually stops. Should be effective to reconnect in most cases. Fixes #439

Thread.currentThread().interrupt();
}

while ( ( retryLimit == 0 || retryCount <= retryLimit ) && bridge.isDisconnected() ){
Copy link
Member

Choose a reason for hiding this comment

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

The spacing style isn't following the existing conventions. Can you reformat this patch to match what exists?

@@ -439,6 +440,7 @@ private void finishConnection() {

@Override
public void connect() {
connecting = true;
Copy link
Member

Choose a reason for hiding this comment

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

It might be easier to follow if you extract this out to another function like:

public void connect() {
    connecting = true;
    try {
        connectInternal();
    } finally {
        connecting = false;
    }
}

private void connectInternal() {
    // previous contents of connect() ...
}

Copy link
Author

Choose a reason for hiding this comment

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

This line didn't change with the addition of the intermediate function, but it is testing out ok on my build.

@@ -265,6 +265,11 @@
<!-- Summary for the preference that forces the service to stay running in the background. -->
<string name="pref_conn_persist_summary">"Force connections to stay connected while in background"</string>

<!-- Name for the retries size preference -->
<string name="pref_retries_title">"Persist retries"</string>
<!-- Description of the retries size preference -->
Copy link
Member

Choose a reason for hiding this comment

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

A bit more context of where this string appears will help. Translators only see these comments and not the context of what is retrying, where in the UI this will be seen, or what it is used for.


bridge.startConnection();

if ( retryCount < 8 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Any kind of constants ("8" here and "2" below) should be extracted out to be in the class near the top.

retryCount++;
Log.d(TAG, String.format("Retries %s session stat: %s", retryCount, bridge.isSessionOpen() ));

while(bridge.isConnecting()){
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this could go on forever and drain batteries. There should be some kind of limit for how long it will wait.

@@ -711,7 +720,43 @@ private void reconnectPending() {
if (bridge == null) {
continue;
}
bridge.startConnection();

int sleepVal = 500;
Copy link
Member

Choose a reason for hiding this comment

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

This should be extracted to a constant.


while(bridge.isConnecting()){
try {
Thread.sleep(500);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you forgot to re-use sleepVal here.

Copy link
Author

Choose a reason for hiding this comment

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

Using minimum retry interval here because it remains constant and this is to wait on the SSH connect which should be more of a known value and not exceed ~30 sec. The sleepVal grows to address more general network issues which may not as quickly resolve.

galexander1 pushed a commit to galexander1/connectbot that referenced this pull request Dec 10, 2016
@kruton
Copy link
Member

kruton commented Feb 10, 2017

NullTransport is still broken in this PR.

@CLAassistant
Copy link

CLAassistant commented May 18, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ kruton
❌ fusiondog
You have signed the CLA already but the status is still pending? Let us recheck it.

@kruton kruton closed this Jul 3, 2020
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.

Reconnecting after short network connectivity loss
3 participants