소스 검색

Fix bug where server may fail to start

There is a race condition where the state may not be set before the
async task checks its value. This causes the server to shutdown
with no warning. This change will fix this bug.
Oliver 8 년 전
부모
커밋
8f9e068bed
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      Sources/HttpServerIO.swift

+ 1 - 1
Sources/HttpServerIO.swift

@@ -75,6 +75,7 @@ public class HttpServerIO {
         self.state = .starting
         let address = forceIPv4 ? listenAddressIPv4 : listenAddressIPv6
         self.socket = try Socket.tcpSocketForListen(port, forceIPv4, SOMAXCONN, address)
+        self.state = .running
         DispatchQueue.global(qos: priority).async { [weak self] in
             guard let strongSelf = self else { return }
             guard strongSelf.operating else { return }
@@ -93,7 +94,6 @@ public class HttpServerIO {
             }
             strongSelf.stop()
         }
-        self.state = .running
     }
 
     public func stop() {