@@ -33,7 +33,7 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
33
33
private readonly addressManager : AddressManager
34
34
private started : boolean
35
35
private lastPublicIp ?: string
36
- private readonly lastPublicIpPromise : DeferredPromise < string >
36
+ private lastPublicIpPromise ? : DeferredPromise < string >
37
37
private readonly check : RepeatingTask
38
38
private readonly onExternalAddressChange ?: ( newExternalAddress : string ) => void
39
39
@@ -46,8 +46,6 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
46
46
47
47
this . checkExternalAddress = this . checkExternalAddress . bind ( this )
48
48
49
- this . lastPublicIpPromise = pDefer ( )
50
-
51
49
this . check = repeatingTask ( this . checkExternalAddress , init . interval ?? 30000 , {
52
50
timeout : init . timeout ?? 10000 ,
53
51
runImmediately : true
@@ -76,7 +74,13 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
76
74
throw new NotStartedError ( 'Not started yet' )
77
75
}
78
76
79
- return this . lastPublicIp ?? raceSignal ( this . lastPublicIpPromise . promise , options ?. signal , {
77
+ if ( this . lastPublicIp != null ) {
78
+ return this . lastPublicIp
79
+ }
80
+
81
+ this . lastPublicIpPromise = pDefer ( )
82
+
83
+ return raceSignal ( this . lastPublicIpPromise . promise , options ?. signal , {
80
84
errorMessage : 'Requesting the public IP from the network gateway timed out - UPnP may not be enabled'
81
85
} )
82
86
}
@@ -94,7 +98,7 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
94
98
}
95
99
96
100
this . lastPublicIp = externalAddress
97
- this . lastPublicIpPromise . resolve ( externalAddress )
101
+ this . lastPublicIpPromise ? .resolve ( externalAddress )
98
102
} catch ( err : any ) {
99
103
this . log . error ( 'could not resolve external address - %e' , err )
100
104
@@ -103,7 +107,7 @@ class ExternalAddressChecker implements ExternalAddress, Startable {
103
107
return
104
108
}
105
109
106
- this . lastPublicIpPromise . reject ( err )
110
+ this . lastPublicIpPromise ? .reject ( err )
107
111
}
108
112
}
109
113
}
0 commit comments