ethgo icon indicating copy to clipboard operation
ethgo copied to clipboard

Need a way to detect connection errors of websocket

Open bynil opened this issue 2 years ago • 2 comments

The error that occurred in stream reading is ignored now. https://github.com/umbracle/ethgo/blob/f671bdb5f607813d015068c18bf61bb54633ab9d/jsonrpc/transport/websocket.go#L91-L98

When we subscribe an event and get no messages, we can not know if the underlying websocket connection is healthy(the network may be down).

Maybe we should add a callback for all unexpected connection errors.

eg. Subscribe(method string, callback func(b []byte), errHandler func(err error)) (func() error, error)

bynil avatar Nov 14 '22 13:11 bynil

The proposal sounds okay. Can you share the error you get from the stream?

ferranbt avatar Nov 14 '22 13:11 ferranbt

The proposal sounds okay. Can you share the error you get from the stream?

I subscribed for new heads:

	events := make(chan []byte, 10000)
	closeFn, err = WsRPC.Subscribe("newHeads", func(b []byte) {
		events <- b
	})

Then disable the network, will get a CloseError from gorilla/websocket: https://github.com/gorilla/websocket/blob/af47554f343b4675b30172ac301638d350db34a5/conn.go#L105

image

bynil avatar Nov 14 '22 13:11 bynil