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

rpc: add timeout to rpc client Unsubscribe #2132

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var (
const (
// Timeouts
defaultDialTimeout = 10 * time.Second // used if context has no deadline
subscribeTimeout = 5 * time.Second // overall timeout ctxc_subscribe, rpc_modules calls
subscribeTimeout = 10 * time.Second // overall timeout eth_subscribe, rpc_modules calls
unsubscribeTimeout = 10 * time.Second // timeout for *_unsubscribe calls
)

const (
Expand Down
7 changes: 5 additions & 2 deletions rpc/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ func (sub *ClientSubscription) unmarshal(result json.RawMessage) (any, error) {
}

func (sub *ClientSubscription) requestUnsubscribe() error {
var result any
return sub.client.Call(&result, sub.namespace+unsubscribeMethodSuffix, sub.subid)
var result interface{}
ctx, cancel := context.WithTimeout(context.Background(), unsubscribeTimeout)
defer cancel()
err := sub.client.CallContext(ctx, &result, sub.namespace+unsubscribeMethodSuffix, sub.subid)
return err
}