Skip to content

Client's SubscribeFilterLogs stops reporting events after some time #23845

Open
@beeb

Description

@beeb

System information

go-ethereum v1.10.8
OS & Version: linux

Expected behaviour

When using ethclient.Client.SubscribeFilterLogs, all events matching the filter are caught.

Actual behaviour

After some time, the script stops reporting new events and it needs to be restarted to start working again.

Steps to reproduce the behaviour

var EthClient *ethclient.Client
// ...
currentBlock, _ := EthClient.BlockNumber(context.Background())
query := ethereum.FilterQuery{
	Addresses: []common.Address{myAddress},
	Topics:    [][]common.Hash{{myTopic}},
	FromBlock: big.NewInt(int64(currentBlock)),
}
logs := make(chan types.Log)
sub, err := EthClient.SubscribeFilterLogs(context.Background(), query, logs)
if err != nil {
	log.Fatal(err)
	return
}

for {
	select {
	case err := <-sub.Err():
		log.Error(err)
		continue
	case vLog := <-logs:
		event, err := MyContract.ParseSomeEvent(vLog)
		if err != nil {
			log.Error(err)
			continue
		}
		// do something here with event

	}
}

Hard for me to convey what needs to be done. I guess try to leave a script running for days and see if it stops catching new events after a while.

I'm not sure what could cause this issue. I automated script restart with cron to try to mitigate this issue but it still happens that the SubscribeFilterLogs stops reporting new events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions