Uninett / Howitz

1 stars 3 forks source link

[BUG]: Can not update events after successful re-connect on lost connection errors #135

Closed podliashanyk closed 2 weeks ago

podliashanyk commented 2 weeks ago

Description

After successful re-connect only "read" operations work on events (like get attrs. logs etc), but "write" operations don't work (like update status, poll etc). All operations work as expected again after a manual page reload.

To reproduce:

  1. Cut network connection and expand any event row
  2. Wait until connection loss is picked up by Howitz in error_handlers (a timeout error alert is displayed)
  3. Reestablish network connection (undo step 1), which is picked up by Howitz handle_lost_connection()
  4. Wait until reconnect to zinolib in error_handlers is successful. You know zinolib connection is working when you can expand collapse event rows again.
  5. See that all "read" operations on events work OK, but all "write" operations fail (until a full page reload) with error:
Traceback (most recent call last):
  File "/Users/ilopod/Desktop/zino-dev/Howitz/howitzvenv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/ilopod/Desktop/zino-dev/Howitz/howitzvenv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/ilopod/Desktop/zino-dev/Howitz/src/howitz/endpoints.py", line 592, in update_event_status
    add_history_res = current_app.event_manager.add_history_entry_for_id(event_id, new_history)
  File "/Users/ilopod/Desktop/zino-dev/zinolib/src/zinolib/controllers/zino1.py", line 639, in add_history_entry_for_id
    event = self._get_event(event_id)
  File "/Users/ilopod/Desktop/zino-dev/zinolib/src/zinolib/controllers/base.py", line 30, in _get_event
    return self.events[event_or_id]
KeyError: 179404

Expected behaviour:

If re-connect was successful, all operations should work as expected without the need for manual page reload.

Context:

hmpf commented 2 weeks ago

Please add where 2, 3 and 4 happens.

podliashanyk commented 2 weeks ago

Updated steps to reproduce

hmpf commented 2 weeks ago

Similar: if testing and turning off the locally running server while logged in, then starting the server again, we now first get "Could not establish connection to UpdateHandler" followed by:

Traceback (most recent call last):
  File "/../.virtualenvs/howitz/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/../.virtualenvs/howitz/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/HOME/../howitz/src/howitz/endpoints.py", line 515, in refresh_events
    removed_events, modified_events, added_events, event_list = refresh_current_events()
  File "/HOME/../howitz/src/howitz/endpoints.py", line 255, in refresh_current_events
    table_events = get_sorted_table_event_list(current_events)
  File "/HOME/../zino/howitz/src/howitz/endpoints.py", line 189, in get_sorted_table_event_list
    for c in events_sorted.values():
AttributeError: 'NoneType' object has no attribute 'values'

The first error is triggered by not being authenticated.

hmpf commented 2 weeks ago

The second exception (AttributeError) happens because there are no events in the cache.

current_events = current_app.cache.get("events"), current_events is None. At this point we need to rebuild the entire list anyway. Either:

  1. we empty the cache ourselves by accident
  2. simplecache does not survive a restart