Closed thoradam closed 1 year ago
So I just copied your code and it worked fine. The curl call return "foo". I've checked this with 5.8 and a 5.i9 weekly from a month or so ago. (I'm currently in transit and haven't had a chance to download latest Xcode etc). When I get back home I'll check with released version of 5.9
Interesting. Some more context:
swift-nio 2.59.0
swift-nio-extras 1.19.1
swift-nio-http2 1.27.0
swift-nio-ssl 2.25.0
Also after having such a request hang (and after cancelling it from the client side), shutting down the server hangs at:
info HummingBird : [Lifecycle] stopping tasks [HTTP Server]
What platform are you using?
macOS 14 (aarch64) and Debian 12 (aarch64), same behavior on both
Ok I've tested swift 5.9 on macOS 14 and could not replicate.
I'll try on my Ubuntu laptop tomorrow.
I can kinda see why this might occur as the 1.0 of swift service lifecycle causes the main thread to stall. This might not work well with Swift concurrency. I have never seen it hang though.
We are in the process of moving away from v1.0 of service lifecycle, but it requires a major version update and we are looking to get some other changes in alongside this change. So it won't happen in the near future.
So I tried this on my Linux laptop and still cannot replicate the issue you are seeing. Would you be able to construct a swift package that demonstrates this issue. Maybe there is some setting I am missing
Maybe there is some setting I am missing
Spot on. This is the culprit:
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
Sorry I wasted your time trying to reproduce this. I understand this is an experimental feature but I was under the impression it only affected compiler warnings/errors and not runtime behavior.
Ok that's interesting. I can repro it now.
I've got a fix as well I think. Hummingbird has the same issue as Vapor where it blocks the main thread when running. I'll steal Vapor's solution. Which in effect runs Hummingbird on a separate DispatchQueue.
Surprised "StrictConcurrency" actually changes code though
Checkout #243 . It is also in v1.9.0
Minimal example:
I'm not very familiar with Swift NIO but I'm assuming this should work. This minimal example might look silly but I'm hitting this issue because I'm using SQLiteNIO to query data for responses but I want to write the code in terms of async/await. Configuring
HBApplication
witheventLoopGroupProvider: .shared(MultiThreadedEventLoopGroup.singleton)
makes no difference.