@@ -45,6 +45,9 @@ import {
45
45
46
46
import { CloudInfo } from '../config' ;
47
47
import { commitJunosSetConfig , executeJunosCommand , getDeviceFacts , getDeviceNetworkCondition } from './Device' ;
48
+
49
+ const sleep = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
50
+
48
51
const sshSessions = { } ;
49
52
50
53
const serverGetCloudInventory = async ( targetOrgs = null , ignoreCaseInName = false ) => {
@@ -718,9 +721,10 @@ export const setupApiHandlers = () => {
718
721
ipcMain . handle ( 'saGetDeviceFacts' , async ( event , args ) => {
719
722
console . log ( 'main: saGetDeviceFacts' ) ;
720
723
724
+ const { address, port, username, password, timeout, upperSerialNumber, bastionHost } = args ;
725
+
721
726
try {
722
- const { address, port, username, password, timeout, upperSerialNumber, bastionHost } = args ;
723
- const reply = await getDeviceFacts (
727
+ let reply = await getDeviceFacts (
724
728
address ,
725
729
port ,
726
730
username ,
@@ -730,8 +734,24 @@ export const setupApiHandlers = () => {
730
734
bastionHost
731
735
) ;
732
736
737
+ if ( reply ?. message ?. toLowerCase ( ) . includes ( 'reset by peer' ) ) {
738
+ console . log ( 'Connection reset by peer, retrying in 3 seconds...' ) ;
739
+ await sleep ( 3000 ) ; // Wait for 3 seconds before retrying
740
+
741
+ reply = await getDeviceFacts (
742
+ address ,
743
+ port ,
744
+ username ,
745
+ password ,
746
+ timeout ,
747
+ upperSerialNumber ,
748
+ bastionHost
749
+ ) ;
750
+ }
751
+
733
752
return { facts : true , reply } ;
734
753
} catch ( error ) {
754
+ console . error ( 'Error getting device facts:' , error ) ;
735
755
return { facts : false , reply : error } ;
736
756
}
737
757
} ) ;
@@ -1037,10 +1057,10 @@ export const setupApiHandlers = () => {
1037
1057
ipcMain . handle ( 'get-device-network-condition' , async ( event , args ) => {
1038
1058
console . log ( 'main: saGetDeviceNetworkCondition' ) ;
1039
1059
1040
- try {
1041
- const { address, port, username, password, timeout, bastionHost, termServer, termPort } = args ;
1060
+ const { address, port, username, password, timeout, bastionHost, termServer, termPort } = args ;
1042
1061
1043
- const reply = await getDeviceNetworkCondition (
1062
+ try {
1063
+ let reply = await getDeviceNetworkCondition (
1044
1064
address ,
1045
1065
port ,
1046
1066
username ,
@@ -1051,12 +1071,41 @@ export const setupApiHandlers = () => {
1051
1071
termPort
1052
1072
) ;
1053
1073
1074
+ if ( reply ?. message ?. toLowerCase ( ) . includes ( 'timed out' ) ) {
1075
+ console . log ( 'Timeout detected, retrying in 3 seconds...' ) ;
1076
+ await sleep ( 3000 ) ;
1077
+ reply = await getDeviceNetworkCondition (
1078
+ address ,
1079
+ port ,
1080
+ username ,
1081
+ password ,
1082
+ timeout ,
1083
+ bastionHost ,
1084
+ termServer ,
1085
+ termPort
1086
+ ) ;
1087
+ } else if ( reply ?. message ?. toLowerCase ( ) . includes ( 'reset by peer' ) ) {
1088
+ console . log ( 'Connection reset by peer detected, retrying in 3 seconds...' ) ;
1089
+ await sleep ( 3000 ) ;
1090
+ reply = await getDeviceNetworkCondition (
1091
+ address ,
1092
+ port ,
1093
+ username ,
1094
+ password ,
1095
+ timeout ,
1096
+ bastionHost ,
1097
+ termServer ,
1098
+ termPort
1099
+ ) ;
1100
+ }
1101
+
1054
1102
return { networkConditionCollect : true , reply } ;
1055
1103
} catch ( error ) {
1104
+ console . error ( 'Network condition error:' , error ) ;
1056
1105
return { networkConditionCollect : false , reply : error } ;
1057
1106
}
1058
1107
} ) ;
1059
-
1108
+
1060
1109
ipcMain . on ( 'restart-app' , ( ) => {
1061
1110
console . log ( 'Received restart-app request...' ) ;
1062
1111
app . relaunch ( ) ; // Relaunch the Electron app
0 commit comments