Skip to content

Commit 8d84a4c

Browse files
committed
Only pop a connection AFTER we have an accepted socket
1 parent 1ccabbe commit 8d84a4c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Suave/Tcp.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ let runServer maxConcurrentOps bufferSize (binding: SocketBinding) (runtime:Http
205205
{ ip = rep.Address; port = uint16 rep.Port }
206206

207207
while not(cancellationToken.IsCancellationRequested) do
208-
let connection : ConnectionFacade = connectionPool.Pop()
209208
try
210209
let! acceptedSocket = listenSocket.AcceptAsync(cancellationToken)
211210

211+
// Only pop a connection AFTER we have an accepted socket
212+
let connection : ConnectionFacade = connectionPool.Pop()
213+
212214
// Set the accepted socket and perform SSL handshake if needed
213215
let! remoteBindingResult = task {
214216
match connection.Connection.transport with
@@ -248,8 +250,6 @@ let runServer maxConcurrentOps bufferSize (binding: SocketBinding) (runtime:Http
248250
// SSL handshake failed, return connection to pool
249251
connectionPool.Push(connection)
250252
with ex ->
251-
// Return connection to pool if accept failed
252-
connectionPool.Push(connection)
253253
// Re-raise if not a cancellation exception
254254
match ex with
255255
| :? OperationCanceledException -> ()

0 commit comments

Comments
 (0)