@@ -111,7 +111,7 @@ func action(cli *cli.Context) error {
111111 bo := backoff .NewExponentialBackOff ()
112112 bo .MaxElapsedTime = 0
113113
114- // this peer is used to allow the node to restart the peer without the need to cancel the module context
114+ // this ctx is used to allow the node to restart the peer without leaving any unwanted open connections
115115 peerCtx , cancel := context .WithCancel (ctx )
116116 defer cancel ()
117117
@@ -144,11 +144,7 @@ func action(cli *cli.Context) error {
144144 return nil
145145 // check if we need to run an update on the peer and only do the update if all the changes are done successfully
146146 case <- time .After (10 * time .Minute ):
147- // if we can get time from substrate then we don't need to update the connection
148- if _ , err := gw .GetTime (); err == nil {
149- continue
150- }
151-
147+ log .Debug ().Msg ("checking for updates in zos config" )
152148 env , err := environment .Get ()
153149 if err != nil {
154150 // skip update if we can't get env
@@ -165,11 +161,19 @@ func action(cli *cli.Context) error {
165161 slices .Sort (updatedSubURLs )
166162 slices .Sort (updatedRelayURLs )
167163
168- // skip update if the urls did not change
164+ // skip update if substrate and relay urls did not change
169165 if slices .Equal (subURLs , updatedSubURLs ) && slices .Equal (relayURLs , updatedRelayURLs ) {
170166 continue
171167 }
172168
169+ // skip update if the old substrate connection is working fine
170+ if ! slices .Equal (subURLs , updatedSubURLs ) {
171+ if _ , err := gw .GetTime (); err == nil {
172+ log .Debug ().Msg ("the open connection is already working, no update needed" )
173+ continue
174+ }
175+ }
176+
173177 newPeerCtx , newCancel := context .WithCancel (ctx )
174178 if err := updatePeer (newPeerCtx , updatedSubURLs , updatedRelayURLs , pair .Seed (), router .Serve ); err != nil {
175179 log .Debug ().Err (err ).Send ()
0 commit comments