Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Subscription] Incorrect microservice IP #78

Open
vladyslav-fenchak opened this issue Feb 8, 2022 · 1 comment · Fixed by #81
Open

[Subscription] Incorrect microservice IP #78

vladyslav-fenchak opened this issue Feb 8, 2022 · 1 comment · Fixed by #81
Labels
bug Something isn't working
Milestone

Comments

@vladyslav-fenchak
Copy link
Contributor

A microservice is restarted but for some reason it does not disconnect correctly from the discovery (it does not send the unsubscribe or the discovery is already restarting and therefore does not receive the request).
later, when it tries to connect to the discovery, it says that it is already connected, so it does not update the IP assuming that it keeps the same one (that would be the bug).
And after restarting the microservice once again, the unsubscribe is done.
And then, after restarting the microservice again, it does the subscribe again, and in this case it registers the correct IP of the microservice.

@vladyslav-fenchak vladyslav-fenchak added the bug Something isn't working label Feb 8, 2022
@garciparedes
Copy link
Member

Here is a theory about the bug reason:

This is the handling function that processes the subscription calls from microservices:

async def post(self):
body = await self.get_body()
redis_client = self.request.app["db_client"]
try:
microservice = Microservice(**body)
except TypeError as exc:
raise web.HTTPBadRequest(text=exc.args[0])
await microservice.save(redis_client)

Here is the save method from Microservice, that performs the set_data calls.

async def save(self, db_client) -> None:
"""Store the instance into the database.
:param db_client: The database client.
:return: This method does not return anything.
"""
microservice_value = {
"name": self.name,
"address": self.address,
"port": self.port,
"endpoints": [
f"{ENDPOINT_KEY_PREFIX}:{endpoint.verb}:{endpoint.path_as_str}" for endpoint in self.endpoints
],
"status": self.status,
}
microservice_key = f"{MICROSERVICE_KEY_PREFIX}:{self.name}"
await db_client.set_data(microservice_key, microservice_value)
for endpoint_key in microservice_value["endpoints"]:
await db_client.set_data(endpoint_key, microservice_key)

The set_data call catches exceptions raised from the database's client, and "transform" them into a True or False response. As the Micorservice.save method does processes those return values, the errors are silenced.

async def set_data(self, key: str, data: dict):
flag = True
try:
await self.redis.set(key, json.dumps(data))
except Exception: # pragma: no cover
flag = False
return flag

I would bet that this bug is related with a small redis pool size, as it only support 10 simultaneous calls. This issue (#70) is intended to increase that value.

pool = aioredis.ConnectionPool.from_url(f"redis://{address}:{port}", password=password, max_connections=10)

@garciparedes garciparedes added this to the v0.1.x milestone Feb 8, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 8, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 8, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
…ption-bug-incorrect-ip

Restyle #78 - Subscription wrong IP
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 9, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 10, 2022
…ption-bug-incorrect-ip

Restyle #78 - Subscription wrong IP
vladyslav-fenchak added a commit that referenced this issue Feb 11, 2022
vladyslav-fenchak added a commit that referenced this issue Feb 11, 2022
@vladyslav-fenchak vladyslav-fenchak linked a pull request Feb 11, 2022 that will close this issue
vladyslav-fenchak added a commit that referenced this issue Feb 11, 2022
vladyslav-fenchak added a commit that referenced this issue Mar 30, 2022
vladyslav-fenchak added a commit that referenced this issue Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants