heedy / connectordb-android

The ConnectorDB android app
Apache License 2.0
8 stars 2 forks source link

Android sync fails with: 'Devices not equal' #10

Closed robbieh closed 5 years ago

robbieh commented 5 years ago

I have set up a connectordb server on Linux that is working with the desktop/laptop client and RESTful calls in general. However, the Android client is giving me trouble. It can successfully sign in, but syncing fails silently. Checking with adb logcat reveals:

12-26 18:03:01.718 29380   591 E DatapointCache: sync: 
12-26 18:03:01.718 29380   591 E DatapointCache: java.lang.Exception: Devices not equal
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.connectordb_android.loggers.DatapointCache.sync(DatapointCache.java:388)
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.connectordb_android.LoggingModule.sync(LoggingModule.java:118)
12-26 18:03:01.718 29380   591 E DatapointCache:        at java.lang.reflect.Method.invoke(Native Method)
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
12-26 18:03:01.718 29380   591 E DatapointCache:        at android.os.Handler.handleCallback(Handler.java:739)
12-26 18:03:01.718 29380   591 E DatapointCache:        at android.os.Handler.dispatchMessage(Handler.java:95)
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
12-26 18:03:01.718 29380   591 E DatapointCache:        at android.os.Looper.loop(Looper.java:148)
12-26 18:03:01.718 29380   591 E DatapointCache:        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
12-26 18:03:01.718 29380   591 E DatapointCache:        at java.lang.Thread.run(Thread.java:818)

The Apache server sitting in front of ConnectorDB as a reverse proxy caught this:

174.103.67.95 - - [26/Dec/2018:23:10:26 +0000] "GET /api%2Fv1?q=this HTTP/1.1" 404 3819 "-" "okhttp/3.11.0"

It looks like the URL is malformed. But I can't figure out why.

Another part of this issue is that the sync failed silently.

dkumor commented 5 years ago

It looks like this is a bug in the java client - I have fixed it in the client itself, and I will publish a version of the android app with this fix tomorrow when I get back home to my dev machine.

That being said, the reason this was not caught before is that ConnectorDB does interpret the %2F as a /, so I think there must be something wrong with your proxy settings, as the app has been tested behind other reverse proxies without issue.

The first thing that comes to mind is ensuring that Apache's /api redirects to ConnectorDB's /api, and a 301 redirect from ConnectorDB is interpreted correctly.

In this case, when given GET /api%2Fv1?q=this HTTP/1.1, ConnectorDB responds with 301 /api/v1?q=this, which then gives the desired answer. I would guess that Apache might not follow the redirects correctly.

You can try fixing it yourself by looking at your Apache settings, or wait for tomorrow's app update which will hopefully fix this issue.

dkumor commented 5 years ago

As a side note, you can check if it works by trying https://cdb.mysite.com/api/v1?q=this in your browser - that should work if you have your reverse proxy set up correctly. Likewise, https://cdb.mysite.com/api%2Fv1?q=this should immediately redirect to the orginal URL and give the desired answer.

robbieh commented 5 years ago

Yes, I just checked and the query to /api/v1/?q=this returns 'nobody'. I was pretty sure Apache was configured reasonably OK because the server/laptop client connects and uploads data without a problem. Also, I believe that encoding a slash as %2F is not the right thing to do per https://tools.ietf.org/html/rfc3986#section-2.2 as the slash is a reserved character. I know that is pedantic :) so thank you for updating the app. I'm eager to test it out.

dkumor commented 5 years ago

I have released an updated version of the app to beta. You can join the beta here: https://play.google.com/apps/testing/com.connectordb_android

You are absolutely right that encoding a slash as %2F is the wrong thing to do - I was simply flabbergasted that this slipped through the tests: it turns out that our http library automatically redirects those, hiding this bug!

Also, you checked /api%2Fv1?q=this, and got the error, right? Your comment only mentions the original url.

Please tell me if the update fixes the issue, or if something else is wrong!

robbieh commented 5 years ago

I'm already in the beta. And I just got the update. The problem has been fixed and I'm seeing data! Thank you!

This should make it more clear what I'm seeing:

'/api/v1/?q=this' + Apache + connectordb: 'nobody' '/api/v1/?q=this' + connectordb: 'nobody' '/api%F2/v1/?q=this' + Apache + connectordb: 404 error '/api%F2/v1/?q=this' + connectordb: 301 redirect

dkumor commented 5 years ago

Great! Thanks for the info!