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

fix: modify unsubscribe cleanup routine and tests #84

Merged
merged 16 commits into from
Oct 25, 2024

Conversation

emizzle
Copy link
Contributor

@emizzle emizzle commented Oct 24, 2024

Closes #79

Modifying the cleanup:

  • Ignore exceptions (other than CancelledError) if uninstallation of the filter fails. If it's the last step in the subscription cleanup, then filter changes for this filter will no longer be polled so if the filter continues to live on in geth for whatever reason, then it doesn't matter.

To fix the subscription filter tests:

  • CancelledError is now caught inside of getChanges. This was causing conditions during subscriptions.close, where the CancelledError would get consumed by the except CatchableError, if there was an ongoing poll happening at the time of close.
  • After creating a new filter inside of getChanges, the new filter is polled for changes before returning.
  • getChanges also does not swallow CatchableError by returning an empty array, and instead re-raises the error if it is not filter not found.
  • eth_getFilterChanges occasionally returns JNull on Windows #79 was fixed by checking the return value of eth_getFilterChanges. If JNull was received, then an empty array is returned.
  • The tests were simplified by accessing the private fields of PollingSubscriptions. That way, there wasn't a race condition for the newFilterId counter inside of the mock.
  • The MockRpcHttpServer was simplified by keeping track of the active filters only, and invalidation simply removes the filter. The tests then only needed to rely on the fact that the filter id changed in the mapping.
  • Because of the above changes, we no longer needed to sleep inside of the tests, so the sleeps were removed, and the polling interval could be changed to 1ms, which not only makes the tests faster, but would further highlight any race conditions if present.

Co-authored-by: Adam Uhlíř [email protected]

emizzle and others added 14 commits October 23, 2024 17:59
Ignore exceptions (other than CancelledError) if uninstallation of the filter fails. If it's the last step in the subscription cleanup, then filter changes for this filter will no longer be polled so if the filter continues to live on in geth for whatever reason, then it doesn't matter.
- add random port
- add more logging
This includes a number of fixes:
- `CancelledError` is now caught inside of `getChanges`. This was causing conditions during `subscriptions.close`, where the `CancelledError` would get consumed by the `except CatchableError`, if there was an ongoing `poll` happening at the time of close.
- After creating a new filter inside of `getChanges`, the new filter is polled for changes before returning.
- `getChanges` also does not swallow `CatchableError` by returning an empty array, and instead re-raises the error if it is not `filter not found`.
- The tests were simplified by accessing the private fields of `PollingSubscriptions`. That way, there wasn't a race condition for the `newFilterId` counter inside of the mock.
- The `MockRpcHttpServer` was simplified by keeping track of the active filters only, and invalidation simply removes the filter. The tests then only needed to rely on the fact that the filter id changed in the mapping.
- Because of the above changes, we no longer needed to sleep inside of the tests, so the sleeps were removed, and the polling interval could be changed to 1ms, which not only makes the tests faster, but would further highlight any race conditions if present.
Copy link
Member

@AuHau AuHau left a comment

Choose a reason for hiding this comment

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

Few comments that I will leave up to you, but otherwise LGTM

@emizzle emizzle merged commit b68bea9 into main Oct 25, 2024
4 checks passed
@emizzle emizzle deleted the fix/subscription-cleanup-adam branch October 25, 2024 03:58
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.

eth_getFilterChanges occasionally returns JNull on Windows
2 participants