Skip to content

Commit

Permalink
views: fix handling of View.is_daemon
Browse files Browse the repository at this point in the history
This patch fixes a regression, introduced in:

	c325458 ("views: add daemonizing support for short running views")

c325458 changed the checks, if a view runtime should be removed from the
server, to make short running deamon-views possible.

When `View.STOP_DAEMON_WHEN_VIEW_FINISHES` was set to `False` and
`View.is_daemon` to `True`, the runtime did not get removed from the server,
when the user closed the tab, and got reconnected, to the same runtime, when
reopening the tab.

When `View.STOP_DAEMON_WHEN_VIEW_FINISHES` was set to `True`, which is the
default, and `View.is_daemon` to `True`, the view should be removed from the
server, when it finishes, and the tab got closed, but instead the runtime
remained on the server, but was not reconnected when reopening the tab.

That meant that the server created a new view runtime on every access of a
page, and did neither reuse or close it, so they built up indefinitely.

This patch fixes this issue, by adding a check to
`ViewRuntime.remove_connection`, if `STOP_DAEMON_WHEN_VIEW_FINISHES` is set,
when the last connection to the runtime gets closed. In this case the runtime
gets removed from the server.

Signed-off-by: Florian Scherf <mail@florianscherf.de>
  • Loading branch information
fscherf committed Feb 10, 2023
1 parent 9254e2e commit 94587cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 12 additions & 1 deletion lona/view_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def __init__(
self.stop_reason = None
self.is_daemon = False

# TODO: remove in 2.0
# compatibility for older Lona application code
self.stop_daemon_when_view_finishes = getattr(
self.view,
'STOP_DAEMON_WHEN_VIEW_FINISHES',
self.server.settings.STOP_DAEMON_WHEN_VIEW_FINISHES,
)

self.view_runtime_id = generate_unique_id(name_space='view_runtimes')
self.state = VIEW_RUNTIME_STATE.NOT_STARTED
self.thread_ident = None
Expand Down Expand Up @@ -474,7 +482,10 @@ def remove_connection(self, connection, window_id=None):

# if the last connection gets closed and the view should
# not continue running in background, it gets stopped
if not self.connections and not self.is_daemon:
if (not self.connections and
self.stop_daemon_when_view_finishes and
not self.is_daemon):

self.stop()

# lona messages ###########################################################
Expand Down
10 changes: 2 additions & 8 deletions lona/view_runtime_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ def get_running_view_runtime(self, user, route, match_info):

continue

# TODO: remove in 2.0
# compatibility for older Lona application code
stop_daemon_when_view_finishes = getattr(
view_runtime.view,
'STOP_DAEMON_WHEN_VIEW_FINISHES',
self.server.settings.STOP_DAEMON_WHEN_VIEW_FINISHES,
)
if (view_runtime.stop_daemon_when_view_finishes and
view_runtime.is_stopped):

if stop_daemon_when_view_finishes and view_runtime.is_stopped:
continue

return view_runtime
Expand Down

0 comments on commit 94587cc

Please sign in to comment.