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

Need a way to detect connection errors of websocket #226

Open
bynil opened this issue Nov 14, 2022 · 2 comments
Open

Need a way to detect connection errors of websocket #226

bynil opened this issue Nov 14, 2022 · 2 comments

Comments

@bynil
Copy link

bynil commented Nov 14, 2022

The error that occurred in stream reading is ignored now.

var err error
buf, err = s.codec.Read(buf[:0])
if err != nil {
if !s.isClosed() {
// log error
}
return
}

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)

@ferranbt
Copy link
Contributor

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

@bynil
Copy link
Author

bynil commented Nov 14, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants