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

feat: skip sending pending payload if URL doesn't match #5834

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

hstove
Copy link
Contributor

@hstove hstove commented Feb 13, 2025

This PR updates the event dispatcher functionality to not send pending requests if the URL is no longer registered as an event observer.

The way pending requests are implemented is that each individual event dispatcher instance checks for pending requests before it sends any new ones. If a node has multiple event observers, this code is ran for each one of them. The first dispatcher is the only one that will actually handle pending requests, if there are any.

Now, the code is updated so that each dispatcher gets pending requests, but then it compares that request to its own URL. If the URL doesn't match, the pending request is skipped.

I think this implementation leaves something to be desired, although I think the ideal change would involve a small refactor of this code. Currently, we're performing IO (O(n)) for each dispatcher for each request, even though we should only ever have pending requests on bootup, and then we should never check again. This would probably be best located in the EventDispatcher struct (of which we only have one) instead of EventObserver.

@hstove hstove requested a review from a team as a code owner February 13, 2025 19:10
@hstove hstove requested a review from obycode February 13, 2025 19:10
@hstove
Copy link
Contributor Author

hstove commented Feb 13, 2025

This is technically ready for review, but working through this led me to some thoughts about a potential refactor of this overall pending request behavior. @obycode would love your thoughts on this!

@hstove hstove requested a review from a team as a code owner February 13, 2025 19:12
@@ -438,6 +438,10 @@ impl EventObserver {
};

for (id, url, payload, timeout_ms) in pending_payloads {
// If the URL is not the same as the endpoint, skip it
if !url.starts_with(&self.endpoint) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is starts_with sufficient here? We should probably be more explicit so that it handles a case where the DB contains the URL "http://localhost:8000/foo" and this EventObserver has the endpoint "http://localhost:80".

Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

I like your idea of refactoring so that it is moved into the EventDispatcher structure. The biggest problem I have with this mechanism is that when there is an old endpoint in the DB, each observer will check it every time they send a payload, adding unnecessary overhead.

@aldur aldur added this to the 3.1.0.0.8 milestone Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Status: 💻 In Progress
Development

Successfully merging this pull request may close these issues.

3 participants