File tree 1 file changed +18
-1
lines changed
packages/cli/src/services
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,23 @@ import { getProxyForUrl } from 'proxy-from-env'
5
5
import { httpsOverHttp , httpsOverHttps } from 'tunnel'
6
6
7
7
const isHttps = ( protocol : string ) => protocol . startsWith ( 'https' )
8
+
9
+ const wait = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) )
10
+
11
+ async function backOffConnect ( url : string , options : mqtt . IClientOptions , retryCount = 0 ) :
12
+ Promise < mqtt . AsyncMqttClient > {
13
+ try {
14
+ return mqtt . connectAsync ( url , options , false )
15
+ } catch ( error ) {
16
+ if ( retryCount > 3 ) {
17
+ throw error
18
+ }
19
+ retryCount += 1
20
+ await wait ( 100 * retryCount )
21
+ return backOffConnect ( url , options , retryCount )
22
+ }
23
+ }
24
+
8
25
export class SocketClient {
9
26
static connect ( ) : Promise < mqtt . AsyncMqttClient > {
10
27
const url = config . getMqttUrl ( )
@@ -39,6 +56,6 @@ export class SocketClient {
39
56
}
40
57
}
41
58
}
42
- return mqtt . connectAsync ( `${ url } ?authenticationScheme=userApiKey` , options , false )
59
+ return backOffConnect ( `${ url } ?authenticationScheme=userApiKey` , options , 0 )
43
60
}
44
61
}
You can’t perform that action at this time.
0 commit comments