@@ -107,7 +107,8 @@ export class NodeCommand extends BaseCommand {
107
107
try {
108
108
const output = await this . k8 . execContainer ( podName , constants . ROOT_CONTAINER , [ 'tail' , '-10' , logfilePath ] )
109
109
if ( output && output . indexOf ( 'Terminating Netty' ) < 0 && // make sure we are not at the beginning of a restart
110
- output . indexOf ( `Now current platform status = ${ status } ` ) > 0 ) {
110
+ ( output . indexOf ( `Now current platform status = ${ status } ` ) > 0 ||
111
+ output . indexOf ( `is ${ status } ` ) ) ) { // 'is ACTIVE' is for newer versions, first seen in v0.49.0
111
112
this . logger . debug ( `Node ${ nodeId } is ${ status } [ attempt: ${ attempt } /${ maxAttempt } ]` )
112
113
isActive = true
113
114
break
@@ -693,33 +694,51 @@ export class NodeCommand extends BaseCommand {
693
694
* @param delay the delay between attempts
694
695
* @returns {Promise<boolean> } true if the proxy is up
695
696
*/
696
- async checkNetworkNodeProxyUp ( nodeId , localPort , maxAttempts = 20 , delay = 5000 ) {
697
- const podArray = await this . k8 . getPodsByLabel ( [ `app=haproxy-${ nodeId } ` , 'fullstack.hedera.com/type=haproxy' ] )
697
+ async checkNetworkNodeProxyUp ( nodeId , localPort , maxAttempts = 30 , delay = 2000 ) {
698
+ const podLabels = [ `app=haproxy-${ nodeId } ` , 'fullstack.hedera.com/type=haproxy' ]
699
+ let podArray = await this . k8 . getPodsByLabel ( podLabels )
698
700
699
701
let attempts = 0
702
+ let status = null
700
703
if ( podArray . length > 0 ) {
701
- const podName = podArray [ 0 ] . metadata . name
702
- this . _portForwards . push ( await this . k8 . portForward ( podName , localPort , 5555 ) )
704
+ let podName = podArray [ 0 ] . metadata . name
705
+ let portForwarder = null
706
+
703
707
try {
704
- await this . k8 . testConnection ( 'localhost' , localPort )
705
- } catch ( e ) {
706
- throw new FullstackTestingError ( `failed to create port forward for '${ nodeId } ' proxy on port ${ localPort } ` , e )
707
- }
708
+ while ( attempts < maxAttempts ) {
709
+ if ( attempts === 0 ) {
710
+ portForwarder = await this . k8 . portForward ( podName , localPort , 5555 )
711
+ await this . k8 . testConnection ( 'localhost' , localPort )
712
+ } else if ( attempts % 5 === 0 ) {
713
+ this . logger . debug ( `Recycling proxy ${ podName } [attempt: ${ attempts } /${ maxAttempts } ]` )
714
+ await this . k8 . stopPortForward ( portForwarder )
715
+ await this . k8 . recyclePodByLabels ( podLabels , 50 )
716
+ podArray = await this . k8 . getPodsByLabel ( podLabels )
717
+ podName = podArray [ 0 ] . metadata . name
718
+ portForwarder = await this . k8 . portForward ( podName , localPort , 5555 )
719
+ await this . k8 . testConnection ( 'localhost' , localPort )
720
+ }
708
721
709
- while ( attempts < maxAttempts ) {
710
- try {
711
- const status = await this . getNodeProxyStatus ( `http://localhost:${ localPort } /v2/services/haproxy/stats/native?type=backend` )
722
+ status = await this . getNodeProxyStatus ( `http://localhost:${ localPort } /v2/services/haproxy/stats/native?type=backend` )
712
723
if ( status === 'UP' ) {
713
- this . logger . debug ( `Proxy ${ podName } is UP. [attempt: ${ attempts } /${ maxAttempts } ]` )
714
- return true
724
+ break
715
725
}
716
726
717
- attempts ++
718
727
this . logger . debug ( `Proxy ${ podName } is not UP. Checking again in ${ delay } ms ... [attempt: ${ attempts } /${ maxAttempts } ]` )
728
+ attempts ++
719
729
await sleep ( delay )
720
- } catch ( e ) {
721
- throw new FullstackTestingError ( `failed to create port forward for '${ nodeId } ' proxy on port ${ localPort } ` , e )
722
730
}
731
+ } catch ( e ) {
732
+ throw new FullstackTestingError ( `failed to check proxy for '${ nodeId } ' on port ${ localPort } : ${ e . message } ` , e )
733
+ } finally {
734
+ if ( portForwarder !== null ) {
735
+ this . _portForwards . push ( portForwarder )
736
+ }
737
+ }
738
+
739
+ if ( status === 'UP' ) {
740
+ this . logger . debug ( `Proxy ${ podName } is UP. [attempt: ${ attempts } /${ maxAttempts } ]` )
741
+ return true
723
742
}
724
743
}
725
744
0 commit comments