Skip to content

Commit

Permalink
Merge pull request #5615 from benjaoming/fix-sync-issues
Browse files Browse the repository at this point in the history
Fix sync issues
  • Loading branch information
Benjamin Balder Bach authored Nov 8, 2019
2 parents a0242d7 + e65b7ab commit c58d603
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/installguide/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Bug fixes

* Remove *pyc files in ka-lite-static (affected 0.17.5 release)
* Fix rare ``GEOSException`` on systems with libgeos :url-issue:`5592`
* Sync'ing timeouts fixed :url-issue:`5615`
* Platform-specific ``*.pyc`` artifacts found in distributed installers, likely harmless :url-issue:`5611`


0.17.5
Expand Down
6 changes: 5 additions & 1 deletion kalite/packages/bundled/fle_utils/internet/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def api_handle_error_with_json_wrapper_fn(request, *args, **kwargs):
except Http404:
raise
except Exception as e:
logger.error("Error in JSON view: {}".format(request.path))
if hasattr(request, 'path'):
logger.error("Error in JSON view: {}".format(request.path))
else:
logger.error("Error in JSON view. Request also has no attribute 'path', so not sure how this got called.")
logger.error(request)
traceback.print_exc()
return JsonResponseMessageError(_("Unexpected error: %(err)s") % {"err": e}, status=500)
return api_handle_error_with_json_wrapper_fn
Expand Down
3 changes: 2 additions & 1 deletion kalite/packages/bundled/securesync/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def __init__(self, host=None, require_trusted=True, verbose=True):
self.url = settings.CENTRAL_SERVER_URL
else:
self.url = "%s://%s/" % (settings.SECURESYNC_PROTOCOL, settings.CENTRAL_SERVER_HOST)
self.parsed_url = urllib2.urlparse.urlparse(self.url)
else:
parsed_url = urllib2.urlparse.urlparse(host)
self.parsed_url = urllib2.urlparse.urlparse(host)
self.url = "%s://%s" % (self.parsed_url.scheme, self.parsed_url.netloc)

self.require_trusted = require_trusted
Expand Down
8 changes: 7 additions & 1 deletion kalite/packages/bundled/securesync/engine/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ class SyncClient(BaseClient):
session = None

def post(self, path, payload={}, *args, **kwargs):
kwargs.setdefault("timeout", 120)
if self.session and self.session.client_nonce:
payload["client_nonce"] = self.session.client_nonce
return super(SyncClient, self).post(path, payload, *args, **kwargs)

def get(self, path, payload={}, *args, **kwargs):
# Set a high timeout since the server can be heavily loaded at times
kwargs.setdefault("timeout", 120)
if self.session and self.session.client_nonce:
payload["client_nonce"] = self.session.client_nonce
# add a random parameter to ensure the request is not cached
Expand Down Expand Up @@ -145,7 +148,10 @@ def close_session(self):

def get_server_device_counters(self):
r = self.get("device/counters")
data = json.loads(r.content or "{}")
try:
data = json.loads(r.content or "{}")
except ValueError:
raise Exception("Did not receive proper JSON data from server. URL: {}\n\nActual data:\n\n{}".format(r.url, r.content))
if "error" in data:
raise Exception("Server error in retrieving counters: " + data["error"])
return data.get("device_counters", {})
Expand Down
2 changes: 1 addition & 1 deletion kalite/packages/bundled/securesync/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_device_counters(**kwargs):

# The local device may have items that haven't incremented the device counter,
# but instead have deferred until sync time. Include those!
if device.is_own_device():
if not getattr(settings, 'CENTRAL_SERVER', False) and device.is_own_device():
cnt = 0
for Model in _syncing_models:
cnt += Model.all_objects.filter(Q(counter__isnull=True) | Q(signature__isnull=True)).count() # include deleted records
Expand Down
8 changes: 4 additions & 4 deletions kalite/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
'level': 'INFO',
},
'django.request': {
'handlers': ['null'],
'level': 'DEBUG',
'handlers': ['console', 'file'],
'level': logging.ERROR,
'propagate': False,
},
'kalite': {
Expand All @@ -132,7 +132,7 @@
},
'cherrypy.access': {
'handlers': ['console', 'file'],
'level': LOGGING_LEVEL,
'level': logging.ERROR,
'propagate': False,
},
'cherrypy.error': {
Expand All @@ -142,7 +142,7 @@
},
'': {
'handlers': ['console', 'file'],
'level': 'INFO',
'level': logging.INFO,
'propagate': False,
},
}
Expand Down

0 comments on commit c58d603

Please sign in to comment.