GithubHelp home page GithubHelp logo

Comments (7)

m29h avatar m29h commented on June 3, 2024

I can (somewhat) confirm this bug. For me when pocketbase closes the connection (after 300 seconds without events as per documentation) the EventLoop just ends (without an exception).

The effect is no more messages are received as the client currently does not realize that the event loop was forcibly closed and also does not try to reconnect to the realtime endpoint.

from pocketbase.

m29h avatar m29h commented on June 3, 2024

@User00092 can you have a look at the PR to see if that solves your original issue?

from pocketbase.

User00092 avatar User00092 commented on June 3, 2024

@m29h
Unfortunately, that does not solve the issue. The exception that httpx raises results in self.kill being set to true. Changing self.kill = True to print('httpx closed connection.'), httpx closed connection. was displayed, and I was still able to receive updates from the server. I don't quite understand how you unsubscribe, so I cannot implement <Object>.kill = True for you. However, if possible, please do.

Here are the changes I made in pocketbase/services/utils/sse.py:
line 8:

import time

line 90-100:

def run(self):
        while not self.kill:
            try:
                for event in self._events():
                    if self.kill:
                        break
                    if event.event in self.listeners:
                        self.listeners[event.event](event)
                time.sleep(0.5) #  Remove some stress off the CPU
            except Exception:
                pass

from pocketbase.

m29h avatar m29h commented on June 3, 2024

@User00092 can you give the output of
pip show httpx so that I can try to reproduce this with the same version. It seems that the exception is not triggered in all httpx library versions...

from pocketbase.

User00092 avatar User00092 commented on June 3, 2024

@m29h of course, here is the information:

Name: httpx
Version: 0.23.3
Summary: The next generation HTTP client.
Home-page:
Author:
Author-email: Tom Christie <[email protected]>
License:
Location: ---\venv\Lib\site-packages
Requires: certifi, httpcore, rfc3986, sniffio
Required-by: pocketbase

from pocketbase.

User00092 avatar User00092 commented on June 3, 2024

I edited the run function to better handle errors, along with the RemoteProtocolError if raised. This allows other exceptions to be handled properly, while handling RemoteProtocolError in a way that doesn't affect the program.

def run(self):
        while not self.kill:
            try:
                for event in self._events():
                    if self.kill:
                        break
                    if event.event in self.listeners:
                        self.listeners[event.event](event)
                time.sleep(1) #  Remove some stress off the CPU (In the event there are multiple threads), also saving system memory.
            except httpx.RemoteProtocolError:
                pass

            except Exception as e:
                print(e)  # Or raise it
                self.kill = True

from pocketbase.

m29h avatar m29h commented on June 3, 2024
Name: httpx
Version: 0.23.3

@User00092 just tried it again with the same version in my environment linux/python 3.11.3 explicitly installing httpx 0.23.3 and still do not get an exception.
The httpx documentation says remote protocol error means "The protocol was violated by the server" this is somewhat not intuitively what one would expect if the other side silently closes the connection.

Is your pocketbase instance maybe behind some reverse proxy or firewall that does something strange?
I digged a bit deeper and it turns out httpx is nowhere raising a RemoteProtocolError but only wrapping an exception that is incoming from the httpcore library. the httpcore library itself wraps the RemoteProtocolError exception incoming from the h11 library.

Looking at the h11 repository i found this (closed) issue: python-hyper/h11#133 from Year 2021.
What version is your h11 library? If it is < 0.14.0 than maybe it helps to upgrade h11 to >=0.14.0

from pocketbase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.