[PR #538] [CLOSED] Fix/ws fragmented recv #38

Closed
opened 2026-07-19 11:34:08 +03:00 by mirror-bot · 0 comments

📋 Pull Request Information

Original PR: https://github.com/Flowseal/tg-ws-proxy/pull/538
Author: @Sceef
Created: 4/2/2026
Status: ❌ Closed

Base: main ← Head: fix/ws-fragmented-recv


📝 Commits (2)

  • f28e4e3 fix(proxy): reassemble fragmented WebSocket messages in recv()
  • 57b686c fix(packaging): bundle setuptools/_vendor for frozen pkg_resources

📊 Changes

4 files changed (+70 additions, -8 deletions)

View changed files

📝 packaging/linux.spec (+8 -1)
📝 packaging/macos.spec (+9 -1)
📝 packaging/windows.spec (+10 -1)
📝 proxy/tg_ws_proxy.py (+43 -5)

📄 Description

Русский

  1. Прокси: фрагментированные WebSocket-сообщения (proxy/tg_ws_proxy.py)
    _read_frame теперь возвращает флаг FIN вместе с opcode и payload.
    recv() собирает одно целое BINARY/TEXT-сообщение по RFC 6455: если первый фрейм с FIN=0, следующие кадры с opcode continuation (0) склеиваются до фрейма с FIN=1.
    PING/PONG по-прежнему обрабатываются между фрагментами и не ломают сборку.
    При нарушении порядка фреймов (continuation без начала или новый data-фрейм до конца предыдущего сообщения) соединение закрывается и возвращается None.
    Зачем: раньше отдавался только первый фрейм, остальные отбрасывались — ломался MTProto-поток и часть медиа (крупные файлы, превью и т.д.) могла не загружаться, если сервер шлёт фрагментированные WS-кадры.

  2. Сборка: PyInstaller и pkg_resources / jaraco (packaging/.spec)
    В datas добавлена рекурсивная упаковка каталога setuptools/_vendor в setuptools/_vendor внутри бандла.
    В hiddenimports добавлен platformdirs.
    Зачем: в setuptools 80+ pkg_resources дописывает setuptools/_vendor в sys.path и импортирует jaraco.
    и platformdirs. В onefile без этого каталога на диске при старте падало: ModuleNotFoundError: No module named 'jaraco' (runtime hook pyi_rth_pkgres).

Изменения внесены в windows, linux и macos spec-файлы.

English

  1. Proxy: fragmented WebSocket messages (proxy/tg_ws_proxy.py)
    _read_frame now returns a FIN flag along with opcode and payload.
    recv() reassembles one logical BINARY/TEXT message per RFC 6455: if the first frame has FIN=0, subsequent continuation (opcode 0) frames are concatenated until a frame with FIN=1.
    PING/PONG are still handled between fragments without breaking reassembly.
    On protocol violations (continuation without a start, or a new data frame before the previous message ends), the connection is closed and None is returned.
    Why: Previously only the first frame was returned and the rest were dropped, which corrupted the MTProto byte stream and could break some media downloads when the server sends fragmented WebSocket frames.

  2. Packaging: PyInstaller vs pkg_resources / jaraco (packaging/.spec)
    datas: recursively bundle setuptools/_vendor into setuptools/_vendor inside the frozen app.
    hiddenimports: add platformdirs.
    Why: Setuptools 80+ pkg_resources prepends setuptools/_vendor to sys.path and imports jaraco.
    and platformdirs. One-file builds did not ship that tree on disk, so startup failed with ModuleNotFoundError: No module named 'jaraco' (via pyi_rth_pkgres).

Applied to Windows, Linux, and macOS spec files.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Flowseal/tg-ws-proxy/pull/538 **Author:** [@Sceef](https://github.com/Sceef) **Created:** 4/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/ws-fragmented-recv` --- ### 📝 Commits (2) - [`f28e4e3`](https://github.com/Flowseal/tg-ws-proxy/commit/f28e4e338453d144d898fb6bd2ab6890ec924c03) fix(proxy): reassemble fragmented WebSocket messages in recv() - [`57b686c`](https://github.com/Flowseal/tg-ws-proxy/commit/57b686c84150dac91acfcaf5bbf67d3a7bba7ed4) fix(packaging): bundle setuptools/_vendor for frozen pkg_resources ### 📊 Changes **4 files changed** (+70 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packaging/linux.spec` (+8 -1) 📝 `packaging/macos.spec` (+9 -1) 📝 `packaging/windows.spec` (+10 -1) 📝 `proxy/tg_ws_proxy.py` (+43 -5) </details> ### 📄 Description Русский 1. Прокси: фрагментированные WebSocket-сообщения (proxy/tg_ws_proxy.py) _read_frame теперь возвращает флаг FIN вместе с opcode и payload. recv() собирает одно целое BINARY/TEXT-сообщение по RFC 6455: если первый фрейм с FIN=0, следующие кадры с opcode continuation (0) склеиваются до фрейма с FIN=1. PING/PONG по-прежнему обрабатываются между фрагментами и не ломают сборку. При нарушении порядка фреймов (continuation без начала или новый data-фрейм до конца предыдущего сообщения) соединение закрывается и возвращается None. Зачем: раньше отдавался только первый фрейм, остальные отбрасывались — ломался MTProto-поток и часть медиа (крупные файлы, превью и т.д.) могла не загружаться, если сервер шлёт фрагментированные WS-кадры. 2. Сборка: PyInstaller и pkg_resources / jaraco (packaging/*.spec) В datas добавлена рекурсивная упаковка каталога setuptools/_vendor в setuptools/_vendor внутри бандла. В hiddenimports добавлен platformdirs. Зачем: в setuptools 80+ pkg_resources дописывает setuptools/_vendor в sys.path и импортирует jaraco.* и platformdirs. В onefile без этого каталога на диске при старте падало: ModuleNotFoundError: No module named 'jaraco' (runtime hook pyi_rth_pkgres). Изменения внесены в windows, linux и macos spec-файлы. English 1. Proxy: fragmented WebSocket messages (proxy/tg_ws_proxy.py) _read_frame now returns a FIN flag along with opcode and payload. recv() reassembles one logical BINARY/TEXT message per RFC 6455: if the first frame has FIN=0, subsequent continuation (opcode 0) frames are concatenated until a frame with FIN=1. PING/PONG are still handled between fragments without breaking reassembly. On protocol violations (continuation without a start, or a new data frame before the previous message ends), the connection is closed and None is returned. Why: Previously only the first frame was returned and the rest were dropped, which corrupted the MTProto byte stream and could break some media downloads when the server sends fragmented WebSocket frames. 2. Packaging: PyInstaller vs pkg_resources / jaraco (packaging/*.spec) datas: recursively bundle setuptools/_vendor into setuptools/_vendor inside the frozen app. hiddenimports: add platformdirs. Why: Setuptools 80+ pkg_resources prepends setuptools/_vendor to sys.path and imports jaraco.* and platformdirs. One-file builds did not ship that tree on disk, so startup failed with ModuleNotFoundError: No module named 'jaraco' (via pyi_rth_pkgres). Applied to Windows, Linux, and macOS spec files. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
mirror-bot added the pull-request label 2026-07-19 11:34:08 +03:00
mirror-bot changed title from [PR #538] [CLOSED] Fix/ws fragmented recv to [PR #538] Fix/ws fragmented recv 2026-07-20 04:09:38 +03:00
mirror-bot changed title from [PR #538] Fix/ws fragmented recv to [PR #538] [CLOSED] Fix/ws fragmented recv 2026-07-20 23:14:26 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Utilities/tg-ws-proxy#38