Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit f217b5a

Browse files
authored
Merge pull request #1787 from OpenBazaar/retryOnConnectionFailAlways
Always retry the connection, not only during the initial connection. [TEST - do not merge]
2 parents 03b8f10 + 9540848 commit f217b5a

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

js/languages/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@
544544
"badSMTPAuthentication": "The username/password combination used failed.",
545545
"goodSMTPAuthentication": "You have successfully connected to the SMTP server.",
546546
"tagIsTooLongHeadline": "The tag is too long",
547-
"tagIsTooLongBody": "Tags cannot be more than %{smart_count} character long. |||| Tags cannot be more than %{smart_count} characters long."
547+
"tagIsTooLongBody": "Tags cannot be more than %{smart_count} character long. |||| Tags cannot be more than %{smart_count} characters long.",
548+
"retryingConnection": "The connection to your node was lost. Retrying connection attempt %{attempt} of %{total}."
548549
},
549550
"pageConnectingMessages": {
550551
"listingConnect": "Connecting to listing ${listing}",

js/start.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ var Polyglot = require('node-polyglot'),
5454
PageConnectModal = require('./views/pageConnectModal'),
5555
Dialog = require('./views/dialog.js'),
5656
loadProfileNeeded = true,
57-
startUpConnectMaxRetries = 4,
58-
startUpConnectRetryDelay = 2 * 1000,
59-
startUpConnectMaxTime = 10 * 1000,
60-
startTime = Date.now(),
57+
startUpConnectMaxRetries = 5,
58+
starutUpConnectCurrentRetries = startUpConnectMaxRetries,
59+
startUpConnectRetryDelay = 3 * 1000,
6160
startUpRetry,
62-
removeStartupRetry,
61+
resetRetry,
6362
onActiveServerSync,
6463
newPageNavView,
6564
newSocketView,
@@ -571,7 +570,7 @@ launchOnboarding = function(guidCreating) {
571570
})();
572571

573572
pageConnectModal.on('cancel', () => {
574-
removeStartupRetry();
573+
resetRetry();
575574
app.getHeartbeatSocket()._socket.onclose = null;
576575
app.getHeartbeatSocket().close();
577576
pageConnectModal.remove();
@@ -594,9 +593,10 @@ app.serverConnectModal.on('connected', () => {
594593
});
595594

596595
app.getHeartbeatSocket().on('open', function() {
597-
removeStartupRetry();
596+
resetRetry();
598597
pageConnectModal.remove();
599-
startUpLoadingModal.open();
598+
//startUpLoadingModal.open();
599+
this.retryConnectionMsg && this.retryConnectionMsg.remove();
600600

601601
if (!profileLoaded) {
602602
// clear some flags so the heartbeat events will
@@ -609,21 +609,33 @@ app.getHeartbeatSocket().on('open', function() {
609609
});
610610

611611
app.getHeartbeatSocket().on('close', startUpRetry = function() {
612-
if (
613-
Date.now() - startTime < startUpConnectMaxTime &&
614-
startUpConnectMaxRetries
612+
if (starutUpConnectCurrentRetries
615613
) {
616614
startUpRetry.timeout = setTimeout(() => {
617-
startUpConnectMaxRetries--;
615+
var retryMsg = {
616+
type: 'warning',
617+
msg: '<i>' + window.polyglot.t('errorMessages.retryingConnection', {attempt: startUpConnectMaxRetries - starutUpConnectCurrentRetries +1, total: startUpConnectMaxRetries}) + '</i>',
618+
duration: false
619+
};
620+
starutUpConnectCurrentRetries--;
618621
app.connectHeartbeatSocket();
622+
if (this.retryConnectionMsg) {
623+
this.retryConnectionMsg.updateMessage(retryMsg);
624+
} else {
625+
this.retryConnectionMsg = app.statusBar.pushMessage(retryMsg);
626+
}
619627
}, startUpConnectRetryDelay);
620628
} else {
629+
this.retryConnectionMsg && this.retryConnectionMsg.remove();
621630
app.serverConnectModal.failConnection(null, app.serverConfigs.getActive())
622631
.open();
623632
}
624633
});
625634

626-
removeStartupRetry = function() {
635+
resetRetry = function() {
636+
starutUpConnectCurrentRetries = startUpConnectMaxRetries;
637+
/* this code removed so the app will automatically reconnect when the internet connection is flaky */
638+
/*
627639
clearTimeout(startUpRetry.timeout);
628640
app.getHeartbeatSocket().off('close', startUpRetry);
629641
app.getHeartbeatSocket().on('close', () => {
@@ -638,6 +650,7 @@ removeStartupRetry = function() {
638650
app.serverConnectModal.open();
639651
}
640652
});
653+
*/
641654
};
642655

643656
app.getHeartbeatSocket().on('message', function(e) {

0 commit comments

Comments
 (0)