tibber / Tibber.SDK.NET

Tibber C# SDK.NET
MIT License
35 stars 5 forks source link

The WebSocket is in an invalid state ('CloseReceived') #6

Open janwiesemann opened 1 year ago

janwiesemann commented 1 year ago

I just wrote a small app which received live measurements and then pushes them into an influx database. Sadly, I've been experiencing some issues.

I'm running this in a Proxmox LXC-Container using netcoreapp3.1. This issues seams to occur, when the LXC is getting backed up.

The project and source is available at: https://github.com/janwiesemann/tibberToInfluxDB. Not all functions use Tibber.SDK.NET, since it started without this library.

You can find the log below.

Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: home 0000000-11111-2222-3333-44444444444 subscription 1: no data received during last 62,524 ms; re-initialize data stream
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: subscribe to 0000000-11111-2222-3333-44444444444
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: web socket operation failed System.Net.WebSockets.WebSocketException (0x80004005): The WebSocket is in an invalid state ('CloseReceived') for this operation. Valid states are: 'Open, CloseSent'
                                                              at System.Net.WebSockets.WebSocketValidate.ThrowIfInvalidState(WebSocketState currentState, Boolean isDisposed, WebSocketState[] validStates)
                                                              at System.Net.WebSockets.ManagedWebSocket.ReceiveAsync(ArraySegment`1 buffer, CancellationToken cancellationToken)
                                                           --- End of stack trace from previous location where exception was thrown ---
                                                              at Tibber.Sdk.RealTimeMeasurementListener.StartListening()
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: System.Net.WebSockets.WebSocketException (0x80004005): The WebSocket is in an invalid state ('CloseReceived') for this operation. Valid states are: 'Open, CloseSent'
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]:    at System.Net.WebSockets.WebSocketValidate.ThrowIfInvalidState(WebSocketState currentState, Boolean isDisposed, WebSocketState[] validStates)
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]:    at System.Net.WebSockets.ManagedWebSocket.ReceiveAsync(ArraySegment`1 buffer, CancellationToken cancellationToken)
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: --- End of stack trace from previous location where exception was thrown ---
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]:    at Tibber.Sdk.RealTimeMeasurementListener.StartListening()
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: listener disposal started
Dec 16 11:15:38 MetricCollector tibberToInfluxDB[1815205]: listener disposal finished

Note: GUIDs changed!

toini commented 1 year ago

@janwiesemann did you figure this one out?

janwiesemann commented 1 year ago

@toini not really, I haven't had the time to do so. I've worked around this issue by hard crashing my application and using a systemd service to automatically restart it a few minutes later.

toini commented 1 year ago

@janwiesemann I have a vague memory i saw something similar before and incorrectly interpreted some of the log rows indicating failure while it had actually been intended behaviour. However im not sure if this is a similar case.

Would you have any instructions on how i could reproduce this myself? What lead this situation?