Skip to content

fix(cooperation): cap tunnel socket read buffers for flow control - #809

Merged
re2zero merged 1 commit into
linuxdeepin:masterfrom
re2zero:pms396845/06-read-buffer-v2
Oct 22, 2026
Merged

re2zero merged 1 commit into
linuxdeepin:masterfrom
re2zero:pms396845/06-read-buffer-v2

Conversation

@re2zero

@re2zero re2zero commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part 6/8 of the reverse tunnel stack (recovery of #802).

This reapplies the reviewed commit on top of the corrected stack because #802 was accidentally merged into its stacked base branch instead of master.

Merge order: #805 → #806 → #807 → #808 → #809 → #810 → #811.
Retargeted to master after #808 merged.

QAbstractSocket buffers incoming bytes in user space without a limit by
default, draining the kernel even when the tunnel credit window is full.
The sender's file server therefore never blocked and reported progress up
to 100% while the receiver was still downloading a large file.

Cap each tunnel stream socket at twice the credit window so TCP
backpressure reaches the writer.

Log: cap tunnel socket read buffers for flow control
PMS: TASK-396845
Influence: large transfers apply TCP backpressure instead of reporting progress the receiver has not received.

Summary by Sourcery

Restore TCP flow control for tunnel streams by limiting socket read buffering.

Bug Fixes:

  • Cap tunnel stream socket read buffers so TCP backpressure is applied when the credit window is full, preventing large transfers from reporting progress before data is received.

Tests:

  • Add coverage verifying that tunnel sockets on both sides use the configured read-buffer limit.

@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR prevents Qt from buffering unlimited incoming tunnel data in user space by setting every stream socket's read buffer to twice the credit window, allowing TCP backpressure to reach the sender; an integration-style test verifies the limit on both sides of a forwarded connection.

Sequence diagram for tunnel socket backpressure

sequenceDiagram
    participant Sender
    participant TCP
    participant ReceiverSocket
    participant TunnelManager
    participant Receiver

    Sender->>TCP: Send stream data
    TCP->>ReceiverSocket: Deliver incoming bytes
    ReceiverSocket->>ReceiverSocket: setReadBufferSize(kReadBufferSize)
    ReceiverSocket->>TunnelManager: readyRead
    TunnelManager->>Receiver: pump
    ReceiverSocket-->>TCP: Buffer capped at 2 * kWindowSize
    TCP-->>Sender: Apply backpressure when buffer is full
Loading

File-Level Changes

Change Details Files
Cap incoming tunnel socket buffering to preserve credit-window TCP backpressure.
  • Define the read-buffer cap as twice the 256 KiB tunnel window.
  • Apply the cap when configuring every stream socket.
  • Add coverage verifying both locally accepted and remotely dialed stream sockets use the configured limit.
src/lib/common/manager/tunnelmanager.h
src/lib/common/manager/tunnelmanager.cpp
tests/manager/tunnelmanager_test.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

lzwind
lzwind previously approved these changes Oct 22, 2026
@re2zero
re2zero force-pushed the pms396845/06-read-buffer-v2 branch from a827357 to 2c5e661 Compare October 22, 2026 07:54
@re2zero
re2zero force-pushed the pms396845/05-http-future-v2 branch from c247b1f to 95bb6c7 Compare October 22, 2026 07:55
@re2zero
re2zero force-pushed the pms396845/06-read-buffer-v2 branch from 2c5e661 to 3947d06 Compare October 22, 2026 08:18
@re2zero
re2zero force-pushed the pms396845/05-http-future-v2 branch 2 times, most recently from 61297ad to 4dc4ef9 Compare October 22, 2026 08:46
@re2zero
re2zero force-pushed the pms396845/06-read-buffer-v2 branch from 3947d06 to c5ee806 Compare October 22, 2026 08:46
QAbstractSocket buffers incoming bytes in user space without a limit by
default, draining the kernel even when the tunnel credit window is full.
The sender's file server therefore never blocked and reported progress up
to 100% while the receiver was still downloading a large file.

Cap each tunnel stream socket at twice the credit window so TCP
backpressure reaches the writer.

Log: cap tunnel socket read buffers for flow control
PMS: TASK-396845
Influence: large transfers apply TCP backpressure instead of reporting progress the receiver has not received.
@re2zero
re2zero force-pushed the pms396845/06-read-buffer-v2 branch from c5ee806 to 2178710 Compare October 22, 2026 08:58
@re2zero
re2zero changed the base branch from pms396845/05-http-future-v2 to master October 22, 2026 08:59
@re2zero
re2zero dismissed lzwind’s stale review October 22, 2026 08:59

The base branch was changed.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了隧道socket读取缓冲区无限制的问题,通过设置QAbstractSocket读取缓冲区上限 来配合信用窗口流控机制。变更仅3个文件,新增61行代码,改动精准且注释完整,包含单元测试 覆盖。语法逻辑正确,代码质量优秀,性能改善明显,无安全漏洞。

|


🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无


💡 改进建议代码示例

// 当前代码已为最佳实践,无需修改。
// tunnelmanager.h
static constexpr int kReadBufferSize = 2 * kWindowSize;  // 512KB,配合信用窗口流控

// tunnelmanager.cpp - setupSocket() 中在连接信号槽前设置
socket->setReadBufferSize(kReadBufferSize);

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@re2zero
re2zero merged commit 34381da into linuxdeepin:master Oct 22, 2026
24 checks passed
@re2zero
re2zero deleted the pms396845/06-read-buffer-v2 branch October 22, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants