mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-10-30 21:47:01 +03:00
[PR #197] [CLOSED] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLI #11
Reference in new issue
Block a user
📋 Pull Request Information
Original PR: https://github.com/Flowseal/tg-ws-proxy/pull/197
Author: @lifeofcapo
Created: 3/16/2026
Status: ❌ Closed
Base:
main← Head:fix/socks5-ipv6-slots-gather-graceful-shutdown📝 Commits (1)
bef6a4ffix(proxy): RFC-compliant IPv6 reply, slots, parallel pool refill, graceful shutdown + cross-platform CLI📊 Changes
5 files changed (+107 additions, -14 deletions)
View changed files
➕
packaging/com.tg-ws-proxy.plist(+25 -0)➕
packaging/tg-ws-proxy.service(+12 -0)📝
proxy/tg_ws_proxy.py(+38 -14)➕
pyproject.toml(+31 -0)➕
requirements-core.txt(+1 -0)📄 Description
Summary
Four focused improvements to
proxy/tg_ws_proxy.pyplus cross-platformpackaging — no behaviour changes for existing Windows users.
Changes
1. Fix IPv6 SOCKS5 reply code (
0x05→0x08)File:
proxy/tg_ws_proxy.pyPreviously, when a client connected via IPv6, the proxy replied with
0x05(Connection refused). Per RFC 1928 §6, the correctcode for an unsupported address type is
0x08(Address type notsupported). This matters because SOCKS5-aware clients (including
Telegram Desktop) use the reply code to decide whether to retry or
report a different error to the user.
2.
__slots__onStatsand_WsPoolFile:
proxy/tg_ws_proxy.pyBoth classes are instantiated once at module level and live for the
entire process lifetime. Adding
__slots__removes the per-instance__dict__, which gives a small but free memory saving and slightlyfaster attribute access — relevant for
Statssince its counters areincremented on every packet.
3. Parallel pool refill via
asyncio.gatherFile:
proxy/tg_ws_proxy.pyThe previous
_refillimplementation created tasks withasyncio.create_taskbut then awaited them one by one in a loop —connections were established sequentially, not in parallel.
Replacing the loop with
asyncio.gathermakes allneededconnectionsrace concurrently, so the pool fills up in the time it takes to complete
the slowest single handshake instead of
needed × handshake_time.4. Graceful WS pool shutdown
File:
proxy/tg_ws_proxy.pyOn shutdown, idle WebSocket connections sitting in
_WsPool._idleweresimply abandoned — the server-side (Telegram DC) would see a TCP RST
instead of a clean WebSocket close frame. The new
_WsPool.close()method drains all buckets and closes every idle connection before the
event loop is cancelled.
close()is called inwait_stop()afterserver.close()but beforetasks are cancelled, so in-flight connections are not affected.
5. Cross-platform CLI entrypoint
New files:
pyproject.toml,requirements-core.txt,packaging/tg-ws-proxy.service,packaging/com.tg-ws-proxy.plistThe proxy core has no OS-specific dependencies — only
windows.pydoes.This PR exposes
proxy/tg_ws_proxy.py:mainas a proper console scriptso Linux and macOS users can install and run the proxy without touching
windows.pyat all.Install and run (any OS):
requirements-core.txtcontains onlycryptography— useful forDocker images or servers where the GUI stack is not needed.
The
packaging/additions follow the existingwindows.specconvention:packaging/tg-ws-proxy.servicepackaging/com.tg-ws-proxy.plistLinux autostart:
macOS autostart:
Testing
windows.pyis untouched.__slots__: confirmed noAttributeErroronStats()and_WsPool()instantiation.gatherrefill: pool fills in parallel; exceptions are caught viareturn_exceptions=True._WsPool.close(): called on stop, logs idle connection count, no impact on active sessions.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #197] [CLOSED] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLIto [PR #197] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLI[PR #197] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLIto [PR #197] [CLOSED] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLI[PR #197] [CLOSED] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLIto [PR #197] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLI[PR #197] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLIto [PR #197] [CLOSED] fixed: RFC-compliant IPv6 reply, __slots__ on hot classes, parallel pool refill, graceful pool shutdown + cross-platform CLI