Dynamic items stop auto-refreshing after 5min (OH 2.0.0, Basic UI)

I am getting some kind of timeout with my Basic UI pages. The dynamic elements (icons, numbers) do auto-refresh for ~5 minutes after entering the page, and then they stop doing that - I need to hit Ctrl-R (manual page refresh) to see the changes. This happens on both Firefox (Win7, Linux) and Chrome (Android). I tried to change a few “timeout” parameters in OH configuration files (e.g. in userdata/jsondb/org.eclipse.smarthome.core.thing.Thing.json , org.ops4j.pax.web.cfg, and jetty.xml), but that didn’t help. I do see the correct events in events.log, it’s just that the page doesn’t refresh automatically after ~5 minutes.

The problem is usually fixed by exiting and then re-entering the page, then it works correctly for another ~5 min.

Does anyone know what’s going on here, and if there is a timeout parameter I can adjust to fix it?

Thanks!

EDIT: I found a workaround for desktop browser (Firefox and Chrome): pressing Ctrl-Shift-R enables the “auto-refresh every minute” feature. This fixes my 5 minute timeout issue. Unfortunately this doesn’t work on Android’s Chrome, which will be my main way of using OpenHab.

Anyone knows the answer? I am stuck here - I can’t really use OpenHab until I figure out how to bypass this 5-minute timeout on my Android cellphone. I tried different browsers with auto refresh plugins - Dolphin, Firefox, plus my original Chrome - nothing seems to help. (This is unlike my desktop, where Firefox with Crtl-Shift-R command does the trick.)

Perhaps there is a way to insert META REFRESH header on OpenHab web pages? I looked into jetty configuration (that’s the OH’s web server, correct?) and couldn’t find anything relevant.

There is a known issue that event updates stop working when you make changes to your openHAB items/sitemap configuration. The workaround is to restart openHAB after you have made such changes.

See also:

On what kind of machine are you running openHAB? Sometimes proxies and firewalls on the machine (or which you use to connect to the machine) can also close connections after a certain timeout. For instance Apache proxies configurations also have a timeout and keepalive option.

Thanks, I already discovered that, but my current issue is different - after I restart OH, re-enter the web page, I can see my dynamic element updating properly - but only for ~5 minutes. After that I have to use manual refresh, or exit the page and re-enter it, and then it again works properly for the next ~5 minutes. I want to know how to extend that period to much longer than 5 minutes.

wborn: Thanks, that sounds plausible. I am using OH2 behind reverse proxy under Nginx (Windows 7). Do you know which Nginx parameter to change to fix my issue?

I am a Apache proxy user myself so I don’t have much Nginx experience. Googling around suggest parameters such as:

proxy_connect_timeout
proxy_send_timeout
proxy_read_timeout

Maybe you can also connect directly to openHAB (bypassing the proxy) to see if it is the root cause? The Nginx logging may also tell you for what reason/timeout a connection is closed.

1 Like

Indeed - this seems to be caused by the reverse proxy, thanks for the tip! When I access OH directly, I do not experience the timeout. I’ll look into Nginx timeout stuff now.

Unfortunately, increasing the Nginx proxy settings didn’t seem to fix the issue on my Android phone. I wish there was a way to add META REFRESH header to OH2 web pages…

Interesting - do see the timeout errors in nginx logs. Here is one example:

2017/02/15 14:34:23 [error] 63920#63972: *55 upstream timed out (10060: A connection attempt failed because the
connected party did not properly respond after a period of time, or established connection failed because connected
host has failed to respond) while reading upstream, client: xxxxx, server: yyyyy, request: “GET /rest/sitemaps/events
/75c93129-6df6-4dc6-b56d-fd1c71efeca2?sitemap=my_home&pageid=my_home HTTP/1.1”, upstream: “http://[::1]:8080
/rest/sitemaps/events/75c93129-6df6-4dc6-b56d-fd1c71efeca2?sitemap=my_home&pageid=my_home”, host: “yyyyy”,
referrer: “https://yyyyy/basicui/app?sitemap=my_home

Any idea what could be causing this timeout error? Here is my nginx proxy configuration (copied from a tutorial here):

        location / {
                proxy_pass                              http://localhost:8080;
                proxy_set_header Host                   $http_host;
                proxy_set_header X-Real-IP              $remote_addr;
                proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto      $scheme;
                satisfy                                 any;
                allow                                   192.168.0.1/24;
                allow                                   127.0.0.1;
                deny                                    all;
                auth_basic                              "Username and Password Required";
                auth_basic_user_file                    .htpasswd;
        }

I am hopeful I nailed this one. Before I placed the three following lines inside the “location / {}” secition in nginx.conf, and it didn’t seem to work:

proxy_connect_timeout 1000;
proxy_send_timeout 1000;
proxy_read_timeout 1000;

But when I moved those three lines outside of location, at the beginning of the “server {}” section, it seemed to work well for ~20 minutes on my cell phone, and then it timed out (but this time no timeout error messages in nginx logs). I’ll experiment with making the timeouts larger still.

That is good news indeed! Now you can also start using openHAB! :slight_smile: :tada:

wborn: Could you please post your reverse proxy settings for Apache? That’s what I tried first, before Nginx, but couldn’t get it to work - it’d fail at OH URLs with a query (with “?”). Do you experience any timeouts issues with Apache?

The ultimate solution to this proxy mess is for OH2 to gain proper authorization mechanism. I read somewhere that that’s a work in progress, so hopefully it will become available soon.

I run Apache on a Raspberry Pi 3 so that may behave a bit different compared to Windows. This is the reverse proxy part of my Apache port 80 configuration which uses a 1 hour timeout:

	ProxyPass        /  http://localhost:8080/ retry=0 timeout=3600
	ProxyPassReverse /  http://localhost:8080/

	<Location "/">
		AuthType Basic
		AuthName "Authentication"
		AuthUserFile "/etc/openhab2/services/.htpasswd"
		Require valid-user

		Order allow,deny
		Allow from all
	</Location>

I usually don’t stay on a page with Android that long and when the display is turned off Android will also close connections . But I did a test yesterday with the screen timeout at 30 minutes and after 20+ minutes items were still properly updated. I’ve tested it with my stock Nexus 5 and Google Pixel phones (Android 6.0.1 and 7.1.1).

But I think that another good solution for this problem would be if the Basic UI of openHAB can recover from these problems itself by trying to reestablishing the connection when it is closed for some reason. So I’ll put in an issue for this.

1 Like

Thanks a lot! I’ll give Apache another try, with your settings.

What I was trying before with Apache was a bit more involved: I tried to use SSL, and also I put ProxyPass and ProxyPassReverse inside the Location / region. I think I’ll try first to reproduce your (simpler) setup, and then will be adding extra factors one at a time.

I agree with you regarding your last point - some kind of auto-refreshing mechanism built into OH would be very useful. I don’t have any timeout issues with my current setup when accessing my reverse proxy from a desktop browser (either Chrome or Firefox) after I enable the browser’s auto-refresh feature (by pressing Crtl-Shift-R). I am pretty sure doing the same on the OH server side would also fix the issue.

Do you know how to add HHTP headers to all OH2 pages? That should be in jetty configuration, correct? If I could find the spot, I would just insert

<meta http-equiv="refresh" content="60">

on all OH2 pages.

I’ve also got SSL working where I use the setup you’ve also been using. But for some reason I never got ProxyPass and ProxyPassReverse working in the Location region for port 80. I also use the X-Forwarded-Proto header because openHAB does not know what protocol is being forwarded. Perhaps adding that solves your API/URL issues?

So this is a snippet of what I use for port 443:

	RequestHeader set X-Forwarded-Proto "https"

	<Location "/">
		AuthType Basic
		AuthName "Authentication"
		AuthUserFile "/etc/openhab2/services/.htpasswd"
		Require valid-user

		Order allow,deny
		Allow from all

		ProxyPass        http://localhost:8080/ retry=0 timeout=3600
		ProxyPassReverse http://localhost:8080/
	</Location>

The meta headers of the Basic UI are stored in the main.html and main_static.html snippets here: https://github.com/eclipse/smarthome/tree/master/extensions/ui/org.eclipse.smarthome.ui.basic/snippets

So you could modify the Basic UI bundle JAR and modify those snippets.

1 Like

Thanks, will try these as well!

@pulsar I’ve submitted the following issue to make the Basic UI more robust regarding connection issues in general:

1 Like

wborn: your Apache reverse proxy configuration works great, thanks again! On a desktop it times out after 1 hour, but on my Android cellphone - after ~20min. It is likely WiFi related timeout. But I think if OpenHab had a built-in auto refresh that would be less of an issue.

1 Like

Thats nice to hear! Hopefully the issue I put in is resolved soon, so Basic UI connection problems are a thing of the past for everyone. :slight_smile:

wborn: Apache now works great for OH2, but I am stuck trying to share the same server with my regular web site stuff. In particular, placing the following Directory /priv section before the Location / with the reverse proxy doesn’t do anything - I get “file not found” reported by Jetty (not Apache), so it looks like the Location / section steals all the requests, including the xxx/priv ones. I am flabbergasted - I thought Directory sections have the highest priority, and Location - the lowest priority? Do you know how I can prevent the reverse proxy stealing xxx/priv requests? Thanks!

    <Directory "H:/WWW/priv">
       AuthType Basic
       AuthName "Restricted Content"
       AuthUserFile "C:/Apache24/conf/.htpasswd"
       Require valid-user
     Order allow,deny
     Allow from all
    </Directory>

 RequestHeader set X-Forwarded-Proto "https"
<Location />
        AuthType Basic
        AuthName "Authentication"
        AuthUserFile "c:/Apache24/conf/.htpasswd"
        Require valid-user

        Order allow,deny
        Allow from all

        ProxyPass        http://localhost:8080/ retry=0 timeout=3600
        ProxyPassReverse http://localhost:8080/
</Location>