Skip to content

presence: Dispose Presence object when store disposed #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Jul 19, 2025

I happened to notice this message getting printed repeatedly in the debug logs (reformatted a bit):

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception:
  NetworkException: HTTP request failed. Client is already closed.
  (ClientException: HTTP request failed. Client is already closed.,
   uri=https://chat.zulip.org/api/v1/users/me/presence)
#0      ApiConnection.send (package:zulip/api/core.dart:175)
<asynchronous suspension>
#1      Presence._maybePingAndRecordResponse (package:zulip/model/presence.dart:93)
<asynchronous suspension>
#2      Presence._poll (package:zulip/model/presence.dart:121)
<asynchronous suspension>

That'd be a symptom of an old Presence continuing to run its polling loop after the ApiConnection has been closed, which happens when the PerAccountStore is disposed. Looks like when we introduced Presence in 5d43df2 (#1619), we forgot to call its dispose method. Fix that now.

The presence model doesn't currently have any tests. So rather than try to add a test for just this, we'll leave it as something to include when we write those tests, #1620.

I happened to notice this message getting printed repeatedly in the
debug logs (reformatted a bit):

    [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception:
      NetworkException: HTTP request failed. Client is already closed.
      (ClientException: HTTP request failed. Client is already closed.,
       uri=https://chat.zulip.org/api/v1/users/me/presence)
    #0      ApiConnection.send (package:zulip/api/core.dart:175)
    <asynchronous suspension>
    zulip#1      Presence._maybePingAndRecordResponse (package:zulip/model/presence.dart:93)
    <asynchronous suspension>
    zulip#2      Presence._poll (package:zulip/model/presence.dart:121)
    <asynchronous suspension>

That'd be a symptom of an old Presence continuing to run its polling
loop after the ApiConnection has been closed, which happens when the
PerAccountStore is disposed.  Looks like when we introduced Presence
in 5d43df2 (zulip#1619), we forgot to call its `dispose` method.
Fix that now.

The presence model doesn't currently have any tests.  So rather than
try to add a test for just this, we'll leave it as something to
include when we write those tests, zulip#1620.
@gnprice gnprice added the maintainer review PR ready for review by Zulip maintainers label Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants