Learn how to fix the Rust Loco Framework error IO(Os { code: 98, kind: AddrInUse, message: "Address already in use" }). This guide covers the causes, troubleshooting steps, and effective solutions to resolve port conflicts in your Loco-based application.

How to solve Loco Framework Error: IO(Os { code: 98, kind: AddrInUse, message: "Address already in use" })

One of the common issues you might encounter when developing with the Loco Framework is that another app already uses the port, causing this common error when launching your app for the first time:

IO(Os { code: 98, kind: AddrInUse, message: "Address already in use" })

In this article, we’ll explore practical steps to identify and resolve port conflicts, ensuring smooth development, and even configure Loco to use alternative ports when necessary.

A. Identify that your loco app isn't running twice

As I was running my first Loco project with Rust, I launched my project as usual:

cargo loco start

And it worked as expected. I worked a little bit on it, and when I tried to relaunch it with cargo loco start, the exception occurred. I noticed then that I had the process running in another terminal, so port 5150 was already in use.

B. Check that no other application is using the same port

The port 5150 is the one used by default in any new Loco Framework app in Rust. While this port is not officially assigned by the IANA to anything specific, there are some applications that use the same port. For example:

  1.  D-Link D-ViewCam
  2. BarTender: Barcode Label Design and Printing Software
  3. Tony Hawk's Pro Skater Series
  4.  Mirth Connect

Check that no other application/process is using the same port. In Windows, you can determine it with the following command in the command prompt:

netstat -ano | findstr :5150

Or if you're using Linux:

sudo lsof -i :5150

If something appears in the list, kill the process and try to relaunch your application.

C. Change your application port

As another option, you can change the port on which your Loco application runs. To do this, change the port property in the config/development.yaml or config/production.yaml depending on your application environment, as mentioned the default port is 5150, so try to change it to another like 5152:

server:
  # Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
  # change the port from 5150 to another, like 5152
  port: 5150
  # Binding for the server (which interface to bind to)
  binding: localhost
  # The UI hostname or IP address that mailers will point to.
  host: http://localhost
  # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
  middlewares:

Then relaunch your application and check whether it works now or not.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors