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

High CPU usage in example when disconnected #43

Open
Gussy opened this issue Aug 23, 2021 · 5 comments
Open

High CPU usage in example when disconnected #43

Gussy opened this issue Aug 23, 2021 · 5 comments

Comments

@Gussy
Copy link

Gussy commented Aug 23, 2021

Using the basic example, the code below will flood the console and cause 100% CPU usage on a single core;

if !ws.IsConnected() {
	log.Printf("Websocket disconnected %s", ws.GetURL())
	continue
}

It's not the most elegant solution, but an easy fix is to do something like this:

if !rm.conn.IsConnected() {
	<-time.After(rm.conn.RecIntvlMin)
	continue
}

Is there a better way to do this? It doesn't look like there's a connected channel to block on.

@Gussy
Copy link
Author

Gussy commented Aug 23, 2021

Looking around at the forks, it seems like digitalocean@5de394a would solve the issue, if the connected channel was exposed in the RecConn struct.

@loeffel-io
Copy link
Member

@Smithx10
Copy link

Is this gonna get pulled in? digitalocean/recws@5de394a#commitcomment-55348888

@Smithx10
Copy link

Looks like there was a PR for it, but never got merged*

@loeffel-io
Copy link
Member

Please see #61

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

3 participants