Skip to content

Commit 8f9e068

Browse files
committed
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.
1 parent eafa10b commit 8f9e068

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/HttpServerIO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class HttpServerIO {
7575
self.state = .starting
7676
let address = forceIPv4 ? listenAddressIPv4 : listenAddressIPv6
7777
self.socket = try Socket.tcpSocketForListen(port, forceIPv4, SOMAXCONN, address)
78+
self.state = .running
7879
DispatchQueue.global(qos: priority).async { [weak self] in
7980
guard let strongSelf = self else { return }
8081
guard strongSelf.operating else { return }
@@ -93,7 +94,6 @@ public class HttpServerIO {
9394
}
9495
strongSelf.stop()
9596
}
96-
self.state = .running
9797
}
9898

9999
public func stop() {

0 commit comments

Comments
 (0)