Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

hysteria outbound: stream blocked on flow control is never released after the local connection ends

Open colituvpn opened this issue 1 month ago • 2 comments

Integrity requirements

  • [x] I have read all the comments in the issue template and ensured that this issue meet the requirements.
  • [x] I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • [x] I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • [x] I searched issues and did not find any similar issues.
  • [x] The problem can be successfully reproduced in the latest Release

Description

Version: Xray-core 26.10.10 (701af60, go1.27.2), hysteria outbound. Server: Hysteria v2.11.0. Also seen with Xray as a library on Android.

When the target of a proxied upload stops reading while keeping its connection open (an upload speed-test server does this once it has measured enough), the Hysteria server stops reading that QUIC stream. The stream's unread data fills the QUIC connection-level flow-control window (20 MB by default; a single stream can hold up to 8 MB), and the outbound's writer for that stream blocks in stream.Write.

When the local connection then ends (the app aborts the upload with a reset), the blocked writer never notices, so interConn.Close() (CancelRead + Close) is only reached when the session is torn down by the connIdle timeout. Until then the stream keeps its share of the connection window. With 3–4 such streams the whole connection stalls: every new TCP request over the hysteria outbound hangs, while UDP over datagrams keeps working. On Android we saw it as Hysteria going dead about a minute into an upload speed test.

With an instrumented server, no STOP_SENDING / reset arrived from the client for the stalled streams until the Xray process was killed.

Suggestion: when a session ends while the outbound's write is blocked, cancel the stream's write side (CancelWrite, i.e. RESET_STREAM) so the blocked Write returns and the server can release the stream's flow-control credit. A server-side mitigation is proposed in HyNetworks/hysteria#1702 / HyNetworks/hysteria#1703; a client-side fix would help with servers that do not have it.

Reproduction Method

Everything on loopback, configs below.

  1. Run the Hysteria server (hysteria server -c server.yaml) and Xray (xray run -c client.json).
  2. Start a TCP sink on 127.0.0.1:19000 that reads about 2 MB from each connection and then stops reading without closing it, and a health target on 127.0.0.1:19001 that answers OK and closes.
  3. Through the SOCKS inbound, open 4 connections to 127.0.0.1:19000 and write as fast as possible for 4 s, then close them with a reset (SO_LINGER 0).
  4. Through the SOCKS inbound, connect to 127.0.0.1:19001: the SOCKS handshake completes but no data ever comes back. In our run 0 of 5 attempts succeeded within 30 s, and none after another 10 s idle.

With a Hysteria server that closes stalled targets (the PR above) the same steps recover in about 8 s.

Client config


{
  "log": {
    "loglevel": "debug",
    "dnsLog": true
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 11080,
      "protocol": "socks",
      "settings": {
        "udp": true
      }
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "hysteria",
      "settings": {
        "version": 2,
        "address": "127.0.0.1",
        "port": 18443
      },
      "streamSettings": {
        "network": "hysteria",
        "security": "tls",
        "tlsSettings": {
          "serverName": "hy.test",
          "alpn": [
            "h3"
          ],
          "pinnedPeerCertSha256": "a06a27ca359c127770ebd5dcb27880b02bad39665879a2d6d9ba0b3c27bbd809"
        },
        "hysteriaSettings": {
          "version": 2,
          "auth": "labpass"
        }
      }
    }
  ]
}

Server config

Hysteria v2.11.0 server (self-signed certificate for hy.test; values generated for this test only):


listen: 127.0.0.1:18443
tls:
  cert: cert.pem
  key: key.pem
auth:
  type: password
  password: labpass
outbounds:
  - name: direct
    type: direct

Client log


Xray 26.10.10 (Xray, Penetrates Everything.) 701af60 (go1.27.2 windows/amd64)
A unified platform for anti-censorship.
2026/10/16 00:43:51.198131 [Info] infra/conf/serial: Reading config: &{Name:client_dbg.json Format:json}
2026/10/16 00:43:51.212673 [Debug] app/log: Logger started
2026/10/16 00:43:51.212673 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:11080
2026/10/16 00:43:51.214005 [Info] transport/internet/tcp: listening tcp on 127.0.0.1:11080
2026/10/16 00:43:51.214535 [Warning] core: Xray 26.10.10 started
2026/10/16 00:43:54.772992 [Info] [3416423630] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:43:54.772992 from tcp:127.0.0.1:49447 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:43:54.773496 [Info] [3416423630] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:43:54.775058 [Debug] [3416423630] transport/internet: dialing to udp:127.0.0.1:18443
2026/10/16 00:43:54.781207 [Debug] transport/internet/hysteria: ECHAccepted false
2026/10/16 00:43:54.781760 [Info] [3416423630] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:43:54.783552 from tcp:127.0.0.1:49451 accepted tcp:127.0.0.1:19000 [proxy]
2026/10/16 00:43:54.784065 [Info] [4057675945] proxy/socks: TCP Connect request to tcp:127.0.0.1:19000
2026/10/16 00:43:54.784065 [Info] [4057675945] app/dispatcher: default route for tcp:127.0.0.1:19000
2026/10/16 00:43:54.784065 [Info] [4057675945] proxy/hysteria: tunneling request to tcp:127.0.0.1:19000 via TCP:127.0.0.1:18443
2026/10/16 00:43:54.784065 [Info] [3984496050] proxy/socks: TCP Connect request to tcp:127.0.0.1:19000
2026/10/16 00:43:54.784065 [Info] [3984496050] app/dispatcher: default route for tcp:127.0.0.1:19000
2026/10/16 00:43:54.784065 [Info] [3984496050] proxy/hysteria: tunneling request to tcp:127.0.0.1:19000 via TCP:127.0.0.1:18443
2026/10/16 00:43:54.784577 from tcp:127.0.0.1:49453 accepted tcp:127.0.0.1:19000 [proxy]
2026/10/16 00:43:54.784577 [Info] [2545005865] proxy/socks: TCP Connect request to tcp:127.0.0.1:19000
2026/10/16 00:43:54.784577 from tcp:127.0.0.1:49454 accepted tcp:127.0.0.1:19000 [proxy]
2026/10/16 00:43:54.784577 [Info] [2545005865] app/dispatcher: default route for tcp:127.0.0.1:19000
2026/10/16 00:43:54.784577 [Info] [2545005865] proxy/hysteria: tunneling request to tcp:127.0.0.1:19000 via TCP:127.0.0.1:18443
2026/10/16 00:43:54.808709 [Info] [1997625179] proxy/socks: TCP Connect request to tcp:127.0.0.1:19000
2026/10/16 00:43:54.808709 [Info] [1997625179] app/dispatcher: default route for tcp:127.0.0.1:19000
2026/10/16 00:43:54.808709 [Info] [1997625179] proxy/hysteria: tunneling request to tcp:127.0.0.1:19000 via TCP:127.0.0.1:18443
2026/10/16 00:43:54.808709 from tcp:127.0.0.1:49452 accepted tcp:127.0.0.1:19000 [proxy]
2026/10/16 00:43:57.068342 [Info] [3777243297] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:43:57.068342 [Info] [3777243297] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:43:57.068342 [Info] [3777243297] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:43:57.068342 from tcp:127.0.0.1:49467 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:43:59.578903 [Info] [930137206] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:43:59.578903 [Info] [930137206] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:43:59.578903 [Info] [930137206] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:43:59.578903 from tcp:127.0.0.1:49468 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:02.081683 from tcp:127.0.0.1:49469 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:02.081683 [Info] [1894855539] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:02.081683 [Info] [1894855539] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:02.081683 [Info] [1894855539] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:04.599530 [Info] [1474632531] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:04.604543 [Info] [1474632531] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:04.604543 [Info] [1474632531] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:04.604543 from tcp:127.0.0.1:49471 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:07.101897 [Info] [954986278] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:07.101897 [Info] [954986278] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:07.101897 [Info] [954986278] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:07.101897 from tcp:127.0.0.1:49472 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:09.611944 [Info] [4046724187] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:09.611944 from tcp:127.0.0.1:49473 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:09.611944 [Info] [4046724187] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:09.611944 [Info] [4046724187] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:12.122361 [Info] [458595516] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:12.122361 [Info] [458595516] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:12.122361 [Info] [458595516] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:12.122361 from tcp:127.0.0.1:49475 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:14.628328 [Info] [1175055309] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:14.628328 [Info] [1175055309] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:14.628328 from tcp:127.0.0.1:49477 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:14.628328 [Info] [1175055309] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:17.143301 [Info] [896530997] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:17.143301 [Info] [896530997] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:17.143301 [Info] [896530997] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:17.143301 from tcp:127.0.0.1:49478 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:19.656599 from tcp:127.0.0.1:49483 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:19.656599 [Info] [2053319113] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:19.656599 [Info] [2053319113] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:19.656599 [Info] [2053319113] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:22.183150 [Info] [2493233773] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:22.183150 [Info] [2493233773] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:22.183150 [Info] [2493233773] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:22.183150 from tcp:127.0.0.1:49485 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:24.693548 [Info] [3189743222] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:24.693548 [Info] [3189743222] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:24.693548 [Info] [3189743222] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:24.693548 from tcp:127.0.0.1:49487 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:27.206123 [Info] [3211666131] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:27.206123 [Info] [3211666131] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:27.206123 [Info] [3211666131] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:27.206123 from tcp:127.0.0.1:49494 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:31.217929 [Info] [987529596] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:31.218433 [Info] [987529596] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:31.218433 [Info] [987529596] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:31.217929 from tcp:127.0.0.1:49496 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:35.222742 [Info] [803214834] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:35.222742 [Info] [803214834] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:35.222742 [Info] [803214834] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:35.222742 from tcp:127.0.0.1:49498 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:39.232753 [Info] [730982010] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:39.232753 [Info] [730982010] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:39.232753 from tcp:127.0.0.1:49500 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:39.232753 [Info] [730982010] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:43.236171 [Info] [100985727] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:43.236171 [Info] [100985727] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:43.236171 [Info] [100985727] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:44:43.236171 from tcp:127.0.0.1:49503 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:57.244956 [Info] [3285122855] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:44:57.244956 [Info] [3285122855] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:44:57.244956 from tcp:127.0.0.1:49511 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:44:57.244956 [Info] [3285122855] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:45:01.254515 [Info] [2499018225] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:45:01.254515 [Info] [2499018225] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:45:01.254515 [Info] [2499018225] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:45:01.254515 from tcp:127.0.0.1:49517 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:45:05.268132 [Info] [3365952314] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:45:05.268132 [Info] [3365952314] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:45:05.268132 from tcp:127.0.0.1:49523 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:45:05.268132 [Info] [3365952314] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:45:09.270582 from tcp:127.0.0.1:49540 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:45:09.270582 [Info] [1710970801] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:45:09.270582 [Info] [1710970801] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:45:09.270582 [Info] [1710970801] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:45:13.283740 [Info] [2612926505] proxy/socks: TCP Connect request to tcp:127.0.0.1:19001
2026/10/16 00:45:13.283740 [Info] [2612926505] app/dispatcher: default route for tcp:127.0.0.1:19001
2026/10/16 00:45:13.283740 [Info] [2612926505] proxy/hysteria: tunneling request to tcp:127.0.0.1:19001 via TCP:127.0.0.1:18443
2026/10/16 00:45:13.283740 from tcp:127.0.0.1:49544 accepted tcp:127.0.0.1:19001 [proxy]
2026/10/16 00:45:17.303974 [Info] [4057675945] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/hysteria: connection ends > stream 8 canceled by remote with error code 0
2026/10/16 00:45:17.304479 [Info] [3984496050] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/hysteria: connection ends > stream 12 canceled by remote with error code 0
2026/10/16 00:45:17.304996 [Info] [2545005865] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/hysteria: connection ends > stream 16 canceled by remote with error code 0
2026/10/16 00:45:17.304996 [Info] [1997625179] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/hysteria: connection ends > stream 20 canceled by remote with error code 0
2026/10/16 00:45:17.311526 [Info] [2612926505] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/hysteria: connection ends > proxy/hysteria: dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı.

Server log


2026-10-16T00:43:49+03:00	INFO	server mode
2026-10-16T00:43:49+03:00	INFO	server up and running	{"listen": "127.0.0.1:18443"}
2026-10-16T00:43:49+03:00	DEBUG	checking for updates	{"version": "Unknown", "platform": "Unknown", "arch": "Unknown", "channel": "Unknown"}
2026-10-16T00:43:49+03:00	DEBUG	no update available
2026-10-16T00:43:54+03:00	INFO	client connected	{"addr": "127.0.0.1:49316", "id": "user", "tx": 0}
2026-10-16T00:43:54+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:43:54+03:00	DEBUG	TCP closed	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:43:54+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000"}
2026-10-16T00:43:54+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000"}
2026-10-16T00:43:54+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000"}
2026-10-16T00:43:54+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000", "error": "readfrom tcp4 127.0.0.1:49456->127.0.0.1:19000: write tcp4 127.0.0.1:49456->127.0.0.1:19000: wsasend: Varolan bir bağlantı uzaktaki bir ana bilgisayar tarafından zorla kapatıldı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000", "error": "writeto tcp4 127.0.0.1:49455->127.0.0.1:19000: read tcp4 127.0.0.1:49455->127.0.0.1:19000: wsarecv: Varolan bir bağlantı uzaktaki bir ana bilgisayar tarafından zorla kapatıldı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000", "error": "readfrom tcp4 127.0.0.1:49457->127.0.0.1:19000: write tcp4 127.0.0.1:49457->127.0.0.1:19000: wsasend: Varolan bir bağlantı uzaktaki bir ana bilgisayar tarafından zorla kapatıldı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19000", "error": "writeto tcp4 127.0.0.1:49458->127.0.0.1:19000: read tcp4 127.0.0.1:49458->127.0.0.1:19000: wsarecv: Varolan bir bağlantı uzaktaki bir ana bilgisayar tarafından zorla kapatıldı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	DEBUG	TCP request	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001"}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}
2026-10-16T00:45:17+03:00	WARN	TCP error	{"addr": "127.0.0.1:49316", "id": "user", "reqAddr": "127.0.0.1:19001", "error": "dial tcp4 127.0.0.1:19001: connectex: Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı."}

colituvpn avatar Oct 15 '26 21:10 colituvpn

Traced on main (10879a4a) and reproduced the scenario on loopback: 4 uploads to a target that stops reading after ~2 MB, each writing ~18 MB over 4 s, aborted with SO_LINGER 0; a 5th request over the same client connection gets no data within 30 s - same result as your run.

The code confirms it: interConn.Close() is CancelRead(0) + stream.Close(), and nothing ever touches the stream's write side. A Write blocked on the flow-control window is only released by CancelWrite ("Write will unblock immediately") or the connection closing - Close() alone does not wake it, and the FIN it queues cannot be delivered while data is stuck behind the window, so the peer is never told to drop the stream's buffered data. That is why nothing recovers until the session and connection are gone.

Plan: in interConn.Close(), when the request side still has a write in flight, cancel the stream's write side (CancelWrite, i.e. RESET_STREAM) instead of only queueing the FIN, so the blocked Write returns and the RESET reaches the peer, releasing the stream's unread data and crediting the connection-level window. Cleanly finished sessions keep the plain close. Note the teardown itself is still driven by the client's idle timeout when the local abort arrives while the writer is wedged (at that point the abort is not observable), but the release then actually happens instead of never, and it should compose with the server-side fix in HyNetworks/hysteria#1703.

I will add a transport test for the blocked-write case and rerun this rig with the fix, then post the branch here.

thatssoheil avatar Oct 15 '26 23:10 thatssoheil

Implemented and verified; opened a pull request: https://github.com/XTLS/Xray-core/pull/7172

Branch fix/hysteria-reset-stalled-writes @ c85f66fa (one file + a transport test). interConn.Close() now resets the stream's write side (CancelWrite) when the request direction still has a write in flight, so the blocked Write returns and the peer drops the unread data and releases its share of the connection-level window. Cleanly finished sessions keep the plain close.

Verified end to end on loopback against a real hysteria v2.11.0 server, using your reproduction (4 uploads to a target that stops reading after ~2 MB, aborted with SO_LINGER 0):

  • before (10879a4a): 11 fresh requests over ~43 s after the abort never succeed;
  • after: the first retry that lands after the aborted sessions idle out succeeds (~6 s after the abort with connIdle forced to 5 s in the test client).

The transport test TestTCPStalledWriteClose fails on main ("stalled write did not return after close") and passes with the change; it also checks that a new stream can send again and that a cleanly finished stream still delivers FIN + all data.

One scope note: the release happens when the aborted session ends (its own idle timeout, or any other teardown of the session) - the local abort itself is not observable once the writer is wedged, so the idle timeout remains the upper bound with stock servers. This composes with the server-side fix in HyNetworks/hysteria#1703 rather than replacing it.

thatssoheil avatar Oct 15 '26 23:10 thatssoheil