-
Notifications
You must be signed in to change notification settings - Fork 661
isOutboundHalfClosureEnabled
closes channel before all writes are flushed
#3139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for filing this Adam, I'll take a look today and see if I can figure out what's happening here, as this should work. |
Ok, this looks like a fundamental bug. We currently process outbound close eagerly: swift-nio/Sources/NIOPosix/BaseStreamSocketChannel.swift Lines 184 to 203 in be266a9
I think this behaviour is just buggy. We should queue up outbound closure behind the writes. |
I didn't expect the issue to be so low level. That's a significant change I imagine |
Certainly a non-trivial one. My instinct is that the fix belongs in the pending writes manager. This is a great find though, because this bug affects all kinds of programs, not just the ones that use NIOAsyncChannel. I really appreciate your hard work root-causing it @adam-fowler. |
@Lukasa Thank you for taking care of this issue! Adam already knew the bug, when I asked him on Discord. I ran into this issue, because I tried to make a get request with If I use curl, it seems that I get all data, but there is then the error: Am I maybe running into a different issue? |
@JoachimM7 you are running into the issue that the workaround should fix. |
@Lukasa The comment from @JoachimM7 about seeing this in HTTP2 got me wondering if you have wrongly diagnosed this. I've implemented the same code as described in the issue on an HTTP2 stream and get the same error message as @JoachimM7. As I understand it you are saying above the issue is related to writes not getting flushed when a connection is closed in |
I may add one more thing to this: When using But when using curl, I do get all the data but just combined with the error |
I suspect there is more than one bug: it wouldn't surprise me at all if the same bug exists in the HTTP/2 stream channel. |
@Lukasa : I don't get any issues when using HTTP1.1 I tried AsyncHTTPClient to be sure, that there is no problem with URLSession. I get the same error when I do |
That's totally fair, but with the example code above I do see an issue with HTTP/1.1, so I think it is in both places. |
I used some breakpoints and I came to this line:
It is called from here:
because |
I am sorry, you can forget my part. I think I found a bug in Hummingbird (hummingbird-project/hummingbird#688), so my issue isn't related here. In addition I found out, that I was wrong with my assumptions: Postman only worked because although I used https, it still went on HTTP/1.1 |
I have a fix for the HTTP2 side of things. It shouldn't really be needed as calling // iterator is the inbound async iterator
while try await iterator.next() != nil {} |
Expected behavior
If I create a
NIOAsyncChannel
withisOutboundHalfClosureEnabled
set to true. When I calloutbound.finish()
I expect that all writes will have been flushed before the channel is closed.This was meant to be a workaround for the fact that
NIOAsyncChannel.executeThenClose
didn't flush writes, but it has the same issue.Steps to reproduce
curl: (18) transfer closed with 672832 bytes remaining to read
If possible, minimal yet complete reproducer code (or URL to code)
Here is a small HTTP server that returns 1000000 bytes in its response
SwiftNIO version/commit hash
be266a9 (latest of this morning)
System & version information
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Darwin Adams-MBP-M1-Max.local 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 arm64
The text was updated successfully, but these errors were encountered: