You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to repeatedly write to a Response body stream results in a promise leak.
This route:
app.on(.GET,"chunked",":count"){ request ->Responsein
guard let count = request.parameters["count", as:Int.self], count >0, count <=100else{returnResponse(status:.badRequest)}letresponse=Response(body:.init(stream:{ writer in
for i in 0..<count {
writer.write(.buffer(.init(integer: i)))}}, count:0))return response
}
Results in a runtime assertion about "leaking promise":
Fatal error: leaking promise created at (file: "/SourcePackages/checkouts/vapor/Sources/Vapor/HTTP/Server/HTTPServerHandler.swift", line: 53): file /SourcePackages/checkouts/vapor/Sources/Vapor/HTTP/Server/HTTPServerHandler.swift, line 53
2020-06-10 17:49:10.639020-0400 firewalk[70185:2526213] Fatal error: leaking promise created at (file: "/SourcePackages/checkouts/vapor/Sources/Vapor/HTTP/Server/HTTPServerHandler.swift", line: 53): file /SourcePackages/checkouts/vapor/Sources/Vapor/HTTP/Server/HTTPServerHandler.swift, line 53
Which is this code:
func serialize(_ response:Response, for request:Request, context:ChannelHandlerContext){
switch request.version.major {case2:
context.write(self.wrapOutboundOut(response), promise:nil)default:
response.headers.add(name:.connection, value: request.isKeepAlive ? "keep-alive":"close")letdone= context.write(self.wrapOutboundOut(response))// Leaked
if !request.isKeepAlive {
done.whenComplete{ _ in
context.close(mode:.output, promise:nil)}}}}
Expected behavior
No leaked promises.
Actual behavior
Runtime assertion.
Environment
Vapor Framework version: 4.8.0
Vapor Toolbox version: N/A
OS version: 10.15.5
The text was updated successfully, but these errors were encountered:
Hello @jshier, coincidentally @Wessi also ran into this issue in #2390 and provides a solution. I think this is a problem that should be primarily clarified in a better error message.
Steps to reproduce
Attempting to repeatedly write to a
Response
body stream results in a promise leak.This route:
Results in a runtime assertion about "leaking promise":
Which is this code:
Expected behavior
No leaked promises.
Actual behavior
Runtime assertion.
Environment
The text was updated successfully, but these errors were encountered: