openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.6k forks source link

[unifi] "java.lang.IllegalArgumentException: Buffering capacity 2097152 exceeded" #9609

Closed CrappyTan closed 2 years ago

CrappyTan commented 3 years ago

OH Unifi binding has stopped working. Initially stopped on 2.5 and remains broken in OH3.

Constant polling gives this error: 18:41:23.594 [WARN ] [l.handler.UniFiControllerThingHandler] - Unhandled exception while refreshing the UniFi Controller unifi:controller:home - java.lang.IllegalArgumentException: Buffering capacity 2097152 exceeded

CloudKey is up to date as are all Unifi devices on my network. image

Error in OH Log image

Multiple posts on the forum for this issue too.

Happy to provide other information or tests if needed

edit: putting log to trace.. api it fails on: https://ubnt.home:8443/api/s/default/stat/sta when called, the response header says it's 338kB. it takes my unifi key 2.6 seconds to return it. it is incredibly verbose; shows the port status, traffic etc of every port on every device (6 devices, around 130 clients across wired and wireless)

Is there a more targeted API to call to get the status?

J-N-K commented 3 years ago

Refactoring to async http handling would be a solution, the buffer size is not limited then.

lolodomo commented 3 years ago

Just for information, this is something I implemented in the remote openHAB binding. Not very difficult. See PR #9320

CrappyTan commented 3 years ago

Would that be possible with this one? Wish I new how to build this then I could contribute as my house is "blind"

CrappyTan commented 3 years ago

Is there anyone who might be able to help me with this? It's rendered my presence detection unworkable. I'm willing to contribute some beer tokens towards a fix for it.

mhilbush commented 3 years ago

I took a quick look at this. The change should be pretty well isolated in UnifiControllerRequest.java. However, I'm not sure how to handle what he's doing with this exception condition. @lolodomo do you know how to handle this special case?

mhilbush commented 3 years ago

@lolodomo Ping

lolodomo commented 3 years ago

You certainly have to keep this special case unchsnged and have it in the two modes.

mhilbush commented 3 years ago

@lolodomo Thanks.

I see what you mean, but I really don't understand what he's doing with the ContentResponse he gets from the exception here. He claims it's an HTTP 401 response, but in the getContent method he doesn't do anything with the ContentResponse from that exception because he just throws a UniFiExpiredSessionException here for the HTTP 401 status code.

lolodomo commented 3 years ago

No., this is weird but apparently he finds the response in the exception cause. So this is a case where the exception is bypaased.

mhilbush commented 3 years ago

Right. He gets the ContentResponse object from the HttpResponseException cause, then he returns that ContentResponse object to his getContent method at which point he checks the HTTP status code. But if the status code is a 401, he just throws another exception in his getContent method.

lolodomo commented 3 years ago

I suppose the responsr he retrieves in the exception has a 200 status code. Why not asking him directly?

mhilbush commented 3 years ago

I thought about it possibly being a 200. That would be the only thing that would make it work.

@mgbowman hasn't been on here in quite a while, but I'll ping him anyway.

openhab-bot commented 3 years ago

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/ubiquiti-unifi-binding-feature-discussion/14520/1137

openhab-bot commented 2 years ago

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/unifi-beta/131156/1