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

event: resubscribe with error handler #22191

Merged
merged 5 commits into from
Jan 21, 2021

Conversation

lukasz-zimnoch
Copy link
Contributor

Added a possibility to pass a custom callback function which will be invoked on subscription error.

This change will allow clients to receive the original subscription error and perform some additional actions like logging to make debugging easier.

Added a possibility to pass a custom
callback function which will be invoked
on subscription error.

This change will allow clients to
receive the original subscription error
and perform some additional actions
like logging to make debugging easier.
@fjl
Copy link
Contributor

fjl commented Jan 20, 2021

Thanks for this change. It looks very useful, but I think we can do it with just one callback. The ResubscribeFunc is called every time the subscription needs to be created, so you can already hook into it and log. We cannot change the signature of ResubscribeFunc, but could make a new type like

// A ResubscribeErrFunc attempts to establish a subscription.
// For every call but the first, the second argument to this function is
// the error that occurred with the previous subscription.
type ResubscribeErrFunc func(context.Context, error) (Subscription, error)

I'm mostly suggesting this because I want to avoid having two callback parameters
when one is enough.

Instead of creating a new callback parameter
one can use a new resubscribe function
type to pass the last subscription error
as its second argument.
@lukasz-zimnoch
Copy link
Contributor Author

Thanks for the review @fjl. I changed the code according to your suggestion.

@fjl fjl merged commit 231040c into ethereum:master Jan 21, 2021
@fjl fjl added this to the 1.10.0 milestone Jan 21, 2021
@lukasz-zimnoch lukasz-zimnoch deleted the resub-on-error-callback branch January 21, 2021 12:50
bulgakovk pushed a commit to bulgakovk/go-ethereum that referenced this pull request Jan 26, 2021
This adds a way to get the error of the failing subscription
for logging/debugging purposes.

Co-authored-by: Felix Lange <fjl@twurst.com>
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.

2 participants