Skip to content

Commit

Permalink
Merge pull request #2132 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
rpc: add timeout to rpc client Unsubscribe
  • Loading branch information
ucwong authored Aug 28, 2024
2 parents e8048b2 + 337938a commit c1744bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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
}

0 comments on commit c1744bf

Please sign in to comment.