Skip to content

Commit 666a370

Browse files
committed
fix: Must flush lineBuffer after SocketTask to prevent data bleeding in keep-alive scenarios
1 parent 8060f05 commit 666a370

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Suave/ConnectionFacade.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ type ConnectionFacade(connection: Connection, runtime: HttpRuntime, connectionPo
337337
}
338338

339339
member this.shutdown() =
340+
if reader.isDirty then
341+
reader.stop()
340342
// Clear the line buffer to prevent data leakage and ensure clean state for reuse
341343
Array.Clear(connection.lineBuffer)
342344
connection.lineBufferCount <- 0
@@ -386,10 +388,7 @@ type ConnectionFacade(connection: Connection, runtime: HttpRuntime, connectionPo
386388
| ex ->
387389
do Console.WriteLine("Error: " + ex.Message)
388390
finally
389-
// Always stop the reader before returning connection to pool
390-
if reader.isDirty then
391-
reader.stop()
391+
do this.shutdown()
392392
if Globals.verbose then
393393
do Console.WriteLine("Disconnected {0}. {1} connected.", clientIp, tracker.ActiveConnectionCount)
394-
do this.shutdown()
395394
}

src/Suave/HttpOutput.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ type HttpOutput(connection: Connection, runtime: HttpRuntime) =
215215
}
216216
| SocketTask f -> task{
217217
do! f (this.Connection, context.response)
218+
// CRITICAL: Must flush lineBuffer after SocketTask to prevent data bleeding
219+
// in keep-alive scenarios. SocketTask is used for file transfers.
220+
do! this.Connection.flush()
218221
}
219222
| NullContent -> task {
220223
if writePreamble then

0 commit comments

Comments
 (0)