BarRaider / obs-websocket-dotnet

C# .NET library to communicate with an obs-websocket server
MIT License
224 stars 104 forks source link

[BUG] JSON parser cannot handle stream response - Error JSON integer 2150501678 is too large or small for an Int32 #114

Closed mj2015 closed 2 years ago

mj2015 commented 2 years ago

Issue Type

Describe the bug After running for a few hours, I got the following exception:

  Error JSON integer 2150501678 is too large or small for an Int32. Path 'outputBytes', line 3, position 27. Newtonsoft.Json.JsonReaderException: JSON integer 2150501678 is too large or small for an Int32. Path 'outputBytes', line 3, position 27.
    at Newtonsoft.Json.JsonTextReader.ParseReadNumber(ReadType readType, Char firstChar, Int32 initialPosition)
    at Newtonsoft.Json.JsonTextReader.ReadNumberValue(ReadType readType)
    at Newtonsoft.Json.JsonTextReader.ReadAsInt32()
    at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
    at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader reader, Object target)
    at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target, JsonSerializerSettings settings)
    at OBSWebsocketDotNet.OBSWebsocket.GetStreamStatus() in /src/obs-websocket-dotnet/OBSWebsocket_Requests.cs:line 405

To Reproduce Steps to reproduce the behavior: Not sure how to reproduce - this is code that runs continuously changing scenes and texts in a display. To keep the connection alive, I read the stream status every 30 seconds. At some point in normal operation, this error occurred. Having restarted my code and OBS, all is back to normal for the moment.

My theory, not having investigated, is that there is a packet index in the response data?

Expected behavior Not to fail.

Versions OBS Version: 28.0.2 Ubuntu OBS WebSocket Version: built in OBS WebSocket Dotnet (this library) Version: 5.0.0.1 OS: Ubuntu 20.04 LTS

mj2015 commented 2 years ago

Having looked at the data sent back, it is obvious what is wrong given the error message. outputBytes should be a long or Int64 to be parsed properly. Obviously after a few hours of streaming, it has sent a lot of bytes.

The code is currently:

    [JsonProperty(PropertyName = "outputBytes")]
    public int BytesSent { get; set; }

and needs to be:

    [JsonProperty(PropertyName = "outputBytes")]
    public long BytesSent { get; set; }

However, I also think all the other ints here should go to longs. I have OBS systems that have been running months, so the duration is going to be large too. Why not play it safe and accept longs?

ywer commented 2 years ago

have the same error ca after ca 4 hours of running