How to kill server when seeing “EADDRINUSE: address already in use”
How to kill server when seeing “EADDRINUSE: address already in use”
https://stackoverflow.com/questions/4075287/node-express-eaddrinuse-address-already-in-use-kill-server
https://levelup.gitconnected.com/how-to-kill-server-when-seeing-eaddrinuse-address-already-in-use-16c4c4d7fe5d
================================
A tutorial on how to kill the process manually when “EADDRINUSE” happens on Mac/Linux and Windows.
The Problem
When trying to restart a Node application, the previous one did not shut down properly, and you may see a “listen EADDRINUSE: address already in use” error such as:
listen EADDRINUSE: address already in useThe cause behind this issue
The reason behind this is that
process.on('exit', ...)
isn't called when the process crashes or is killed. It is only called when the event loop ends, and sinceserver.close()
sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event.
Solution
The proper fix for the application would be
- On crash, do
process.on('uncaughtException', ..)
- And on kill do
process.on('SIGTERM', ..)
When this EADDRINUSE issue has already happened, in order to resolve it, you need to kill the process manually. In order to do that, you need to find the process id (PID) of the process. You know the process is occupying a particular port on your machine or server.
Kill the process manually
For Mac/Linux
To find the process id (PID) associated with the port
⇒ lsof -i tcp:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 44475 chen5 31u IPv4 0x8b1721168764e4bf 0t0 TCP *:strexec-s (LISTEN)
Then to kill the process
kill -9 44475
Use -9
option to make sure the process dies immediately
If you get permissions errors, you may need to use the sudo
keyword, for example:
sudo kill -9 44475
=============================
First, you would want to know which process is using port 3000
sudo lsof -i :3000
this will list all PID listening on this port, once you have the PID you can terminate it with the following:
kill -9 {PID}
=============================
For Windows
Solution 1: Task Manager
Open the Task Manager application (taskman.exe), from either the Processes or Services tab sort by the PID column. To display the PID column, right-click the header row and select PID from the list. Right-click the process you want to stop and select End task.
Solution 2: Use Command prompt
Open a CMD window in Administrator mode by navigating to Start > Run > type cmd > right-click Command Prompt, then select Run as administrator.
source from Google SearchUse the netstat command lists all the active ports. The -a
switch displays all ports in use, not just the ports associated with the current user. The -n
option stops a hostname lookup (which takes a long time). The -o
option lists the process ID that is responsible for the port activity. The findstr
command matches the header row that contains the PID string, and the port you are looking for, in a port format with the preceding colon, is :3000.
C:\Users\admin>netstat -ano|findstr "PID :3000"
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 18264
To kill this process (the /f is force):
taskkill /pid 18264 /f
相关文章
- vcenter提示连不上cannot connect to vcenter single sign-on server 7444/sts/stsservice/vsphere.local
- Idea连接mysql 报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
- convert datetime to timestamp in ms sql server
- string to base64 or base64 to string in ms sql server
- 解决报错:错误1130- Host xxx is not allowed to connect to this MariaDb server
- SharePoint 2013 中的SQL Server 安全
- Creating Dynamic T-SQL to Move a SQL Server Database
- SQL SERVER 修改数据库名称(包括 db.mdf 名称的修改)
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds
- check sql server edition (version 版本)
- Windows Server AppFabric 安装文档
- 解决Lost connection to MySQL server during query错误方法
- SQL Server 日常维护经典应用
- The server is temporarily unable to service your request due to maintenance downtime or capacity pro
- 浅析基于SQL Server PDW大数据解决方案
- Introduction to Change Data Capture (CDC) in SQL Server 2008[转]
- Sql Server系列:子查询
- Install TightVNC Server in RHEL/CentOS and Fedora to Access Remote Desktops
- Darwin Streaming Server 简介
- How to Rename a Server 2008 Domain(近期可能要用到的准备资料)
- How to Export Mailboxes with Exchange Server 2010 SP1(带状态查看,清除请求,归档备份)
- SharePoint Server 2013开发之旅(一):新的开发平台和典型开发场景介绍
- 解决问题Can’t connect to local MySQL server through socket