How to stop and run Vapor again in Xcode?

Viewed 535

I've followed the Vapor tutorial to create a hello app. In Xcode, when I run the Run scheme on my Mac, the app starts and runs as I can see by opening http://localhost:8080/. After making some changes in the code, I stop the Run scheme and I expect the Vapor server to shutdown. However, it continues to serve requests.

Message from debugger: The LLDB RPC server has exited unexpectedly. Please file a bug if you have reproducible steps.
Program ended with exit code: -1

Obviously when I make some changes and run the Run scheme again, I get the following runtime error:

Swift/ErrorType.swift:200: Fatal error: Error raised at top level: bind(descriptor:ptr:bytes:) failed: Address already in use (errno: 48)
Program ended with exit code: 9

How do I stop or restart the server?

2 Answers

This is a long standing issue with Xcode/LLDB. You have a few options:

  • attach to the process and stop it via Xcode
  • run killall Run
  • run lsof -i :8080 to find the process connected to port 8080 and then kill <process_id> (this is useful if you're running multiple apps side by side and only want to terminate the orphaned one)

This is quite frustrating and to be honest I dont know why this happens, but I do the following to terminate the process:

In Xcode,

  • Go to Debug -> Attach to Process
  • At the very top of the sub-menu is: Likley targets section with an entry Run (nnnn). It will have an icon of the Terminal application
  • Click to attach
  • Then stop the Xcode Run in the usual way.

Out of interest, the next time you run your vapor app, if you open the Debug Navigator, at the top you will see the Terminal icon with Run PID nnnn. Where nnnn is the PID. If you go to Debug -> Attach to Process again, you can see this at the top of the sub-menu as before. But you wont be able to attach to it because it is already being debugged.

Hope this helps you or someone in the future.

Related