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

API_streams shows zero connected clients #7116

Closed
Molodax opened this issue Apr 15, 2017 · 10 comments
Closed

API_streams shows zero connected clients #7116

Molodax opened this issue Apr 15, 2017 · 10 comments

Comments

@Molodax
Copy link

Molodax commented Apr 15, 2017

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):
Starting 0.33 till the current 0.42.x

Python release (python3 --version):

Component/platform:
API stream sensor

Description of problem:
The sensor shows 0 connected clients al the time, however, if you add logger in your configuration file, the sensor works as expected.

Expected:
Correct and independent functionality of the sensor.

Problem-relevant configuration.yaml entries and steps to reproduce:

Traceback (if applicable):

Additional info:

@Molodax
Copy link
Author

Molodax commented May 25, 2017

Have anyone noticed that since version 0.45.x the number of connected clients is increasing every time when your refresh browser and never goes down. It looks like the sessions never closes due to timeout.

@jonathanweinberg
Copy link

I've noticed this behavior also post 0.45.x as well.

@tiszavolgyi
Copy link

Yes, number of connected clients is increasing for me as well every time when I refresh browser and never goes down... Logger turned on with default: warning and using HA 0.47.0 version.

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@richrd
Copy link

richrd commented Oct 12, 2017

I'm on HA 0.54.0 and after getting the api_streams sensor to work the value just increases and never goes down just like @Molodax @jonathanweinberg and @tiszavolgyi said.

I have these set in my config.

logger:
  default: info

sensor:
  - platform: api_streams

@richrd
Copy link

richrd commented Oct 12, 2017

I think I found the reason why the connections never go down (at least for websocket connections).
This is where the connection count is increased or decreased: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/sensor/api_streams.py#L38
The closing of the connection is reported in two different places in two different ways:

1) https://github.com/home-assistant/home-assistant/blob/5779d64e98961f32ab03915b49087155bdedc9c4/homeassistant/components/websocket_api.py#L351

2) https://github.com/home-assistant/home-assistant/blob/5779d64e98961f32ab03915b49087155bdedc9c4/homeassistant/components/websocket_api.py#L393

The detection only notices one of those, but not the other.
Adding the following to api_streams.py fixes this helps a bit, but doesn't completely fix it:

            elif record.args[1] == 'Connection closed by client':
                self.entity.count -= 1

EDIT:
Actually it seems that if I just close the homeassistant tab, the finally block in handle(self, request) isn't executed. No idea why but seems that the sockets are just left hanging.
This might be related: aio-libs/aiohttp#2309
EDIT2:
Seems like the some of the connections are eventually closed, but it takes about 15 minutes to happen after the browser tab is closed. I can reproduce this semi reliably. Sometimes the tab close will be noticed and the connection count goes down, sometimes it takes 15 minutes to register, and some are never registered. I currently have over 20 connections from yesterday that never close.

@Mariusthvdb
Copy link
Contributor

had it running fine for a couple of days, and correctly displaying the number of clients, it suddenly starts going up here also...

is there a way to show which clients are connected? Might that be a way to a solution?

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@Molodax
Copy link
Author

Molodax commented Mar 28, 2018

The sensor seems to work correctly but only if you have logger in your configuration file.

@richrd
Copy link

richrd commented Apr 16, 2018

I have logger, but the count still never goes down.

@Molodax Molodax closed this as completed Oct 13, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants