Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

socks握手时的bufio会吞掉客户端流水线发送的首段payload,进而导致UoT v2客户端的每条流都会失败

オープン
#113 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@Snowy117 がすでに取り組んでいます。

2026年10月6日 から。

  • #114 @Snowy117 による — オープン

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go
領域
networking

調査の方向性

Start with protocol/socks/handshake.go, especially the reader and handler handoff locations linked in the issue, and trace how buffered bytes are handled after the SOCKS5 CONNECT request. Reproduce with the supplied Python client, sending the greeting, CONNECT request, UoT header, and first frame together; done when the pipelined case succeeds as well as the staged case without losing payload bytes.

索引モデルが issue の本文から書いたものです。

説明

问题

SOCKS5客户端可以把首个payload和CONNECT请求放在同一个TCP段里发送,以此节省一个RTT。但是sing就会把这部分字节丢掉。

对UoT v2客户端来说,就表现为每一条UoT流都在请求头处失败:客户端把发往 sp.v2.udp-over-tcp.arpa 的 CONNECT、UoT请求头和第一个数据帧写在同一个缓冲区里一次发出,服务端日志为

INFO  inbound/socks[in]: inbound connection to sp.v2.udp-over-tcp.arpa:0
ERROR inbound/socks[in]: process connection from 127.0.0.1:58042: UoT read request: unknown address family: 152

复现

注意要一次性发出全部内容

import socket, struct, time

MAGIC = b'sp.v2.udp-over-tcp.arpa'
greeting = bytes([5, 1, 0])
connect = bytes([5, 1, 0, 3, len(MAGIC)]) + MAGIC + b'\x00\x00'
uot_request = bytes([1, 1, 192, 168, 1, 1, 0x75, 0x3A])   # isConnect, ATYP=IPv4, addr, port
frame = struct.pack('>H', 8) + b'WFE1\x00\x00\x00\x01'

s = socket.create_connection(('127.0.0.1', 1080))   # sing-box v1.14.2 SOCKS5 Listen
s.sendall(greeting + connect + uot_request + frame)
time.sleep(1)
s.close()

socks inbound + direct outbound:

客户端 sing侧结果
发 greeting、读回复;发 CONNECT、读回复;之后再发UoT请求 inbound UoT connect connection to 192.168.1.1:30001;OK没有问题
一次写完全部内容 UoT read request: EOF;之后还有数据帧的话就是unknown address family: N;失败了

原因

handshake.go里握手通过reader *std_bufio.Reader解析,bufio每次 fill都把整块缓冲读满,但CONNECT交给handler的是原始连接:

https://github.com/SagerNet/sing/blob/6f21f2425a959912c37d2ef43d61e2a663315dea/protocol/socks/handshake.go#L158
https://github.com/SagerNet/sing/blob/6f21f2425a959912c37d2ef43d61e2a663315dea/protocol/socks/handshake.go#L228

把流的中间当成了开头

主要言語
Go
スター
131
フォーク
117
平均マージ
1時間 42分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SagerNet/sing のほかの issue

SagerNet/sing の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。