New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failing to start on Mac due to in-use port fails to return #132
Comments
you can kill your localhost by running:
PID is the second field. Then, kill that process:
|
That's not really an option. Firstly because I don't know what's already got the port and I might need it. Second because I need to start Hummingbird from Swift. So shell scripting it's a possibility at this point. |
Been digging into this and the problem seems to be related to the interaction of several pieces of code. In public func start() throws {
let promise = self.eventLoopGroup.next().makePromise(of: Void.self)
self.lifecycle.start { error in
if let error = error {
self.logger.error("Failed starting HummingBird: \(error)")
promise.fail(error)
} else {
self.logger.info("HummingBird started successfully")
promise.succeed(())
}
}
try promise.futureResult.wait()
} Then there is the code in NIO's @inlinable
internal func _resolve(value: Result<Value, Error>) {
if self.futureResult.eventLoop.inEventLoop {
self._setValue(value: value)._run()
} else {
self.futureResult.eventLoop.execute {
self._setValue(value: value)._run()
}
}
} And @inlinable
internal func execute(_ task: @escaping () -> Void) {
// nothing we can do if we fail enqueuing here.
try? self._schedule0(ScheduledTask(id: self.scheduledTaskCounter.add(1), task, { error in
// do nothing
}, .now()))
} and finally in @inlinable
internal func execute(_ task: @escaping () -> Void) {
// nothing we can do if we fail enqueuing here.
try? self._schedule0(ScheduledTask(id: self.scheduledTaskCounter.add(1), task, { error in
// do nothing
}, .now()))
} When a port is already take, the application's In iOS In OSX however it's quite different. At this point execution stops and the future is never resolved. Which means that Hummingbird is hung, not able to either execute or exit. My guess (because I don't have deep enough knowledge of NIO, etc) is that NIO is unable to execute the resolve of the future because it's trying to run it on the same thread that has been stopped by the So, if I'm reading this right, any error generated by Hummingbird attempting to start in a POSIX environment would cause it to hang rather than return. How this can be fixed I don't know because I don't have the knowledge to resolve this. Is there an alternative way to "wait", or can the code somehow bypass the queuing of the error resolving, or is there some other way to handle this? |
If another process has the port, you can't bind to it, so you can't start your server. What do you expect Hummingbird to do at that point? |
I expect it to stop with an error. It does that on iOS. On OS X it queues the error to the future, but then cannot execute that because the thread is locked. So it just hangs. The calling code doesn't get anything. No error. Nothing. |
I do remember seeing something recently about using RunLoop I'll need to do some more investigation |
Yeah. That's what I did in #133 but the code I have there is probably pretty hacky as it was the first thing I could think of. Did solve the issue though :-) PS. I'm also working through this on Linux where some of the other guys in my team are using the code I've got. So far (apart from this issue) everything is working fine. |
#135 should fix this |
This is now merged into main. Can you verify this works for you |
Cool. Will get back to you. |
Hi, I've run Hummingbird on both OSX and Linux using the |
Cheers, I should hopefully get a release out this morning |
Not sure if I'm right about this. I have a Mac command line target that's starting a Hummingbird server.
What appears to be happening is that if the port I ask it to start on is already taken, Hummingbird fail and hangs at this point:
This doesn't seem to occur when running the same startup code on an iOS simulator, just when running via a Mac command.
Any clues how I might resolve this?
The text was updated successfully, but these errors were encountered: