Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Remote closing connection leads to unhandled exceptions in _sync

未关闭
#278 6 条评论 6 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
api, backend

调研方向

先阅读 matrix_client/client.py 中 listen_forever 和 _sync 附近的代码,然后通过 matrix_client/api.py 跟踪 sync 请求。复现或跟踪已报告的远程断开连接,并确定对后台线程异常的预期处理方式;只有在该行为以及任何面向用户的指导都得到明确定义和覆盖后,该 issue 才算完成。

由索引模型根据 Issue 内容生成。

描述

I just wanted to point out, that without an error callback, the current implementation of having listen_forever in a thread created by the library can lead to unhandled exceptions that cannot be intercepted.

Following traceback sometimes occurs during running my currently developed bridge software, which atm. lets matrix clients run with start_listener_thread() - it happens very occasionally. I only get a real palpable error later, when i try to send with one of those clients - so until then it does not get noticed. i can also provide more information, but i think this is a more general issue.
I also should mention, my client was connected via https externally

I am of course rewriting it to handle threading on my own anyway so it is not an issue for me i hope in the future - however documentation should probably point out problems like this to the user, so he can prepare or set a general exception handler, and maybe if you keep a "simple we do the threading" solution, an exception callback for the thread would also be a solution.

from pip:
used package: matrix-client==0.3.2

the error logged:
matrix_client.client [ERROR]: Exception thrown during sync

the traceback:

Traceback (most recent call last):
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/myproject/directory/lib/python3.5/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/util/retry.py", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/myproject/directory/lib/python3.5/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/myproject/directory/lib/python3.5/site-packages/matrix_client/api.py", line 670, in _send
    verify=self.validate_cert
  File "/myproject/directory/lib/python3.5/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/myproject/directory/lib/python3.5/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/myproject/directory/lib/python3.5/site-packages/requests/adapters.py", line 495, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/myproject/directory/lib/python3.5/site-packages/matrix_client/client.py", line 473, in listen_forever
    self._sync(timeout_ms)
  File "/myproject/directory/lib/python3.5/site-packages/matrix_client/client.py", line 555, in _sync
    response = self.api.sync(self.sync_token, timeout_ms, filter=self.sync_filter)
  File "/myproject/directory/lib/python3.5/site-packages/matrix_client/api.py", line 105, in sync
    api_path=MATRIX_V2_API_PATH)
  File "/myproject/directory/lib/python3.5/site-packages/matrix_client/api.py", line 673, in _send
    raise MatrixHttpLibError(e, method, endpoint)
matrix_client.errors.MatrixHttpLibError: Something went wrong in GET requesting https://myproject.host/_matrix/client/r0/sync: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
主要语言
Python
星标
266
派生
118
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

matrix-org/matrix-python-sdk 的其他 Issue

查看 matrix-org/matrix-python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。