iOS: OutputStream.write return value 0 treated as fatal in bound stream writers
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 ios/Sources/GutenbergKitHTTP/RequestBody.swift 中的 RequestBody.makePipedFileSliceStream 和 ios/Sources/GutenbergKit/Sources/Media/MediaUploadServer.swift 中的 DefaultMediaUploader.writeAll 开始。阅读两者如何处理 OutputStream.write(_:maxLength:) 的结果,然后验证返回值为 0 时不会中止上传,而返回值为负数时仍会中止上传。完成标准是,两个绑定流 writer 都能一致地处理文档中说明的返回情况,并且不会让 URLSession 一直等待字节。
由索引模型根据 Issue 内容生成。
描述
Summary
The writeAll pattern used in bound-stream-pair writers treats OutputStream.write(_:maxLength:) returning 0 as a fatal error. Apple's documentation defines a 0 return as "a fixed-length stream has reached its capacity." It is unclear whether a bound stream pair (from Stream.getBoundStreams(withBufferSize:)) qualifies as a "fixed-length stream," meaning write() could return 0 when the internal buffer is full rather than blocking.
If 0 is returned as a backpressure signal, the current code silently aborts the write, closes the stream, and leaves URLSession waiting for Content-Length bytes that never arrive — causing the upload to hang.
Locations
RequestBody.makePipedFileSliceStream—ios/Sources/GutenbergKitHTTP/RequestBody.swift(~line 236)DefaultMediaUploader.writeAll—ios/Sources/GutenbergKit/Sources/Media/MediaUploadServer.swift(introduced in #419, same pattern)
Both use:
let result = output.write(base.advanced(by: written), maxLength: ...)
if result <= 0 { return }
Apple documentation
OutputStream.write(_:maxLength:): returns 0 for "a fixed-length stream that has reached its capacity"CFWriteStreamWrite: "If the stream is not full, this call blocks until at least one byte is written"- Neither document explicitly states whether bound stream pairs block or return 0 when the buffer is full
Suggested fix
Distinguish 0 (retry) from -1 (error):
if result == -1 { return false }
if result == 0 {
Thread.sleep(forTimeInterval: 0.001)
continue
}
Risk
Low probability in practice — uploads would need to outpace URLSession's read rate long enough to fill the 65KB buffer. More likely with large files on slow connections.
- 主要语言
- JavaScript
- 星标
- 29
- 派生
- 7
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 83
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
wordpress-mobile/GutenbergKit 的其他 Issue
-
[Type] Bug Android
难度 2/5 1-3 小时 新手友好度 79/100
wordpress-mobile/GutenbergKit#847 ·
维护者通常 1 天内回复
-
[Type] Bug iOS
难度 2/5 1-3 小时 新手友好度 77/100
wordpress-mobile/GutenbergKit#846 ·
维护者通常 1 天内回复
-
[Type] Bug [Type] Code Quality iOS
难度 2/5 1-3 小时 新手友好度 88/100
wordpress-mobile/GutenbergKit#668 ·
维护者通常 1 天内回复
-
[Type] Bug [Type] Performance iOS
难度 2/5 1-3 小时 新手友好度 88/100
wordpress-mobile/GutenbergKit#666 ·
维护者通常 1 天内回复
-
[Type] Bug iOS
难度 2/5 1-3 小时 新手友好度 78/100
wordpress-mobile/GutenbergKit#664 ·
维护者通常 1 天内回复
查看 wordpress-mobile/GutenbergKit 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
sebastienros/jint#4449 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
remotion-dev/remotion#12957 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
Ebony-Vinyl/dsh-our-free-model#759 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
RocketChat/EmbeddedChat#1416 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复