Skip to content

Conversation

@anitarua
Copy link
Contributor

@anitarua anitarua commented Jun 11, 2025

Closes https://github.com/momentohq/dev-eco-issue-tracker/issues/1157

Pubsub clients should do some bookkeeping of number of active subscriptions to be able to gracefully reject new subscribe requests rather than letting them silently queue up on the client.

Updated the client to use a pool of 4 unary grpc managers by default to match the other SDKs.
The stream managers use the existing with_max_subscriptions configuration to statically set the number of grpc managers in the stream pool.

Created a sync and async subscription_initialization test suite like in other SDKs. Unfortunately, it appears these tests cannot be run against momento-local. The credential provider must use insecure_channel() for http connections to momento-local, but apparently under the hood that means only one underlying TCP connection is created, but the tests are written expecting to exercise multiple grpc channels. I've excluded these tests from CI because they cannot be run against momento-local or the live service since they require a subscriptions limit greater than the default.

@anitarua anitarua marked this pull request as ready for review June 11, 2025 17:36
@anitarua anitarua requested a review from a team June 11, 2025 17:37
Comment on lines +176 to +179
def __del__(self) -> None:
if not self._decremented:
self._decrement_stream_count()
self._decremented = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we implementing __del__? Do we need this somewhere? If not then we should remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented __del__ in order to be able to decrement the number of active streams when a subscription closes. Is there a better method to implement this? Or is there a super() equivalent I should call here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern for this is to use a context manager. I don't think we can do this now though since it would break the API and expectations existing users have.

@anitarua anitarua requested a review from malandis June 13, 2025 23:26
Comment on lines +176 to +179
def __del__(self) -> None:
if not self._decremented:
self._decrement_stream_count()
self._decremented = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern for this is to use a context manager. I don't think we can do this now though since it would break the API and expectations existing users have.

Comment on lines +181 to +185
def unsubscribe(self) -> None:
if not self._decremented:
self._decrement_stream_count()
self._decremented = True
self._client_stream.cancel() # type: ignore[misc]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's called in the tests / can be called by end users to immediately free up a stream

@anitarua anitarua requested a review from malandis June 18, 2025 18:30
@anitarua anitarua merged commit 0d5e514 into main Jun 18, 2025
11 checks passed
@anitarua anitarua deleted the subscriptions-bookkeeping branch June 18, 2025 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants