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
I tried to implement a HTTP echo server and it always crashes with a promise leak
import Vapor
varenv=tryEnvironment.detect()tryLoggingSystem.bootstrap(from:&env)letapp=Application(env)defer{ app.shutdown()}
app.on(.POST,"echo"){ request ->ResponseinreturnResponse(body:.init(stream:{ writer in
request.body.drain{ body in
switch body {case.buffer(let buffer):return writer.write(.buffer(buffer))case.error(let error):return writer.write(.error(error))case.end:return writer.write(.end)}}}, count:0))}try app.run()
Repro:
run the above program
echo -ne 'POST /echo HTTP/1.1\r\n\r\n' | nc localhost 8080 (note this doesn't send a content-length or transfer-encoding header which means it's EOF framed (message ends on EOF, NIO will handle that though and send you an .end on EOF)).
Result:
Fatal error: leaking promise created at (file: ".../checkouts/vapor/Sources/Vapor/HTTP/Server/HTTPServerHandler.swift", line: 53): file .../checkouts/vapor/Sources/Vapor/HTTP/Server/HTTPServerHandler.swift, line 53
The text was updated successfully, but these errors were encountered:
weissi
changed the title
HTTP echo server crashes with unfulfilled promise
HTTP echo server crashes with unfulfilled promise if client misbehaves
Jun 10, 2020
weissi
changed the title
HTTP echo server crashes with unfulfilled promise if client misbehaves
HTTP echo server crashes with unfulfilled promise if client uses EOF framing
Jun 10, 2020
I tried to implement a HTTP echo server and it always crashes with a promise leak
Repro:
echo -ne 'POST /echo HTTP/1.1\r\n\r\n' | nc localhost 8080
(note this doesn't send acontent-length
ortransfer-encoding
header which means it's EOF framed (message ends on EOF, NIO will handle that though and send you an.end
on EOF)).Result:
The text was updated successfully, but these errors were encountered: