Skip to content

Commit

Permalink
work-around the VPN node address broadcasting issue (#707)
Browse files Browse the repository at this point in the history
* work-around the VPN node address broadcasting issue
* address remarks by @johny-b
  • Loading branch information
shadeofblue authored Oct 5, 2021
1 parent 0c3fab9 commit d4e67e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions yapapi/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ async def add_node(self, node_id: str, ip: Optional[str] = None) -> Node:

return node

async def _refresh_node(self, node: Node):
logger.debug("refreshing node %s", node)
try:
await self._net_api.add_node(self.network_id, node.node_id, node.ip)
except ApiException as e:
# the `409 Conflict` shouldn't happen with the latest yagna (0.8.0-rc7)
# but we're adding the work around as the error is mostly harmless anyway
if e.status == 409:
logger.warning(
"Could not refresh node %s (%s). network_id=%s",
node.node_id,
node.ip,
self.network_id,
)
else:
raise

async def refresh_nodes(self):
await asyncio.gather(*[self._refresh_node(n) for n in self._nodes.values()])

async def remove(self) -> None:
"""Remove this network, terminating any connections it provides."""
self._state_machine.stop()
Expand Down
7 changes: 7 additions & 0 deletions yapapi/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@ def change_state(event: Union[ControlSignal, ExcInfo] = (None, None, None)) -> N
batch = batch_task.result()
except StopAsyncIteration:
change_state()

# work-around an issue preventing nodes from getting correct information about
# each other on instance startup by re-sending the information after the service
# transitions to the running state
if self.network and instance.state == ServiceState.running:
await self.network.refresh_nodes()

except Exception:
logger.warning("Unhandled exception in service", exc_info=True)
change_state(sys.exc_info())
Expand Down

0 comments on commit d4e67e0

Please sign in to comment.