Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Do not report `AcceptFailed` when timing out in `stream_socket_accept()` for non-blocking listeners

未關閉
#23,879 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
c, php
領域
networking

研究方向

Start at the implementation behind stream_socket_accept() and trace how a non-blocking listener with a zero timeout records stream errors. Reproduce the issue with the provided PHP script, then find the relevant stream socket tests and add coverage for the expected no-error result while preserving genuine accept failures.

由索引模型根據 Issue 內容生成。

描述

Bug Category: Streams Status: Needs Triage
Description

The following code:

<?php

$server = stream_socket_server(
    'tcp://127.0.0.1:0',
    context: stream_context_create([
        'stream' => [
            'error_mode' => StreamErrorMode::Silent,
            'error_store' => StreamErrorStore::All,
        ],
    ]),
);
stream_set_blocking($server, false);
var_dump(stream_socket_accept($server, 0));

foreach (stream_last_errors() as $error) {
    var_dump($error);
}

Resulted in this output:

bool(false)
object(StreamError)#3 (5) {
  ["code"]=>
  enum(StreamErrorCode::AcceptFailed)
  ["message"]=>
  string(35) "Accept failed: Connection timed out"
  ["wrapperName"]=>
  string(6) "stream"
  ["severity"]=>
  int(2)
  ["terminating"]=>
  bool(true)
}

But I expected this output instead:

bool(false)

While it is technically true that accepting a new connection failed, no clients waiting is an expected situation when using a non-blocking listener socket (in particular with a zero-timeout). It is a common pattern to call accept() until no more client connections are returned to quickly drain the listening queue after the polling API marked the listener as readable instead of sending it through the whole polling logic again.

By treating the timeout as a failure with the generic AcceptFailed error code, it becomes impossible to distinguish this situation from genuine failures (such as exhausted file descriptors) without inspecting the message, which is particularly annoying when combined with StreamErrorMode::Exception and greatly diminishes the ergonomics of PHP 8.6’s new polling API and stream error handling logic.

PHP Version
PHP 8.6.0-dev (cli) (built: Sep 24 2026 09:04:46) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.6.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0-dev, Copyright ©, by Zend by Perforce
Operating System

No response

主要語言
C
星號
40.4k
分支
8.2k
平均合併
2 天 15 小時
30 天內合併 PR
113

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。