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

Websocket hanging watchdog #106

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion blockchain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blockchain
import (
"context"
"sync"
"time"

gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry"
Expand Down Expand Up @@ -183,7 +184,8 @@ func (c *Client) ListenEvents(

// Invoke listeners.
g.Go(func() error {
for blockEvents := range eventsC {
select {
case blockEvents := <-eventsC:
for callback := range c.eventsListeners {
err := (*callback)(blockEvents.Events, blockEvents.Number, blockEvents.Hash)
if err != nil {
Expand All @@ -197,6 +199,11 @@ func (c *Client) ListenEvents(
return err
}
}
// Watchdog for the websocket. It silently hangs sometimes with no error nor new events. In
// all Cere blockchain runtimes we have `pallet-timestamp` which makes at least one event
// (System.ExtrinsicSuccess for the timestamp.set extrinsic) per block.
case <-time.After(60 * time.Second):
Copy link
Contributor

Choose a reason for hiding this comment

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

might be either move to constant or make it configurable in client creation method and set it as a default (still in constant)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, I made it a constant.

return context.DeadlineExceeded
}

return ctx.Err()
Expand Down
Loading