         return dataTask
     }
 }
+
+extension GCDWebServer {
+    var safeToStart: Bool {
+        // prevents a crash where although the http server reports running is false, attempting to start while GCDWebServer->_source4 is not null causes abort() to be called which kills the app. GCDWebServer.serverURL == nil is equivalent to GCDWebServer->_source4 == NULL.
+        return !running && serverURL == nil
+    }
+    
+    var safeToStop: Bool {
+        // prevents a crash where http server must actually be running to stop it or abort() is called which kills the app.
+        return running
+    }
+}

        dispatch_barrier_async(self._concurrentSubscriptionQueue, { () -> Void in
            // needs to be running in order to get server url for the subscription message
            let httpServer = self._httpServer
            if !httpServer.running {
                httpServer.startWithPort(self._httpServerPort, bonjourName: nil)
            }
            
            let serverURL = httpServer.serverURL
            
            // Stop http server if it's not needed further
            self.startStopHTTPServerIfNeeded(self._subscriptions)
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
                serverURL != nil ? closure(eventCallBackURL: NSURL(string: self._eventCallBackPath, relativeToURL: serverURL)!) : closure(eventCallBackURL: nil)

                LogError("\(errorDescription)")
            }
        })
    }
    
    private func startHTTPServer() -> Bool {
        if _httpServer.safeToStart {
            return _httpServer.startWithPort(_httpServerPort, bonjourName: nil)
        }
        
        return false
    }
    
    private func stopHTTPServer() -> Bool {
        if _httpServer.safeToStop {
            _httpServer.stop()
            return true
        }
        
        return false
    }
}

