Skip to content

Commit

Permalink
Fix bug where server may fail to start
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oliveroneill committed Jun 5, 2018
1 parent eafa10b commit 8f9e068
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/HttpServerIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -93,7 +94,6 @@ public class HttpServerIO {
}
strongSelf.stop()
}
self.state = .running
}

public func stop() {
Expand Down

0 comments on commit 8f9e068

Please sign in to comment.