[TIL] μ—λŸ¬λ…ΈνŠΈπŸ“• - [Node js] address already in use

June hyoung ParkΒ·2020λ…„ 9μ›” 7일
5

NodeJs

λͺ©λ‘ 보기
5/8
post-thumbnail

κΉ”λ”ν•˜κ²Œ κ΅¬λ™λ˜λ˜ Express μ„œλ²„κ°€ κ°‘μžκΈ° μ½˜μ†”μ°½μ— λœ»λ°–μ˜ μ—λŸ¬λ₯Ό λΏœμ—ˆλ‹€. μž¬λ°ŒλŠ”κ±΄ 'address already in use'μ—λŸ¬μ—λ„ λΆˆκ΅¬ν•˜κ³  μ„œλ²„λ„ 잘 μž‘λ™λ˜κ³  ν΄λΌμ΄μ–ΈνŠΈμ™€μ˜ 톡신에도 μ•„λ¬΄λŸ° 이상이 μ—†μ—ˆλ‹€λŠ” 것이닀.

address already in use

events.js:292
[0]       throw er; // Unhandled 'error' event
[0]       ^
[0] 
[0] Error: listen EADDRINUSE: address already in use :::5000
[0]     at Server.setupListenHandle [as _listen2] (net.js:1313:16)
[0]     at listenInCluster (net.js:1361:12)
[0]     at Server.listen (net.js:1447:7)
[0]     at Function.listen (/Users/8stepsMAC/Downloads/Project/MERN-Shopping-mall/node_modules/express/lib/application.js:618:24)
[0]     at Object.<anonymous> (/Users/8stepsMAC/Downloads/Project/MERN-Shopping-mall/server/index.js:55:5)
[0]     at Module._compile (internal/modules/cjs/loader.js:1138:30)
[0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
[0]     at Module.load (internal/modules/cjs/loader.js:986:32)
[0]     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
[0]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
[0]     at internal/main/run_main_module.js:17:47
[0] Emitted 'error' event on Server instance at:
[0]     at emitErrorNT (net.js:1340:8)
[0]     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
[0]   code: 'EADDRINUSE',
[0]   errno: 'EADDRINUSE',
[0]   syscall: 'listen',
[0]   address: '::',
[0]   port: 5000
[0] }

보톡 이 μ—λŸ¬λŠ” ν˜„μž¬ μž‘μ—…μ€‘μΈ ν”„λ‘œμ νŠΈ νŒŒμΌμ—μ„œ λ‹€λ₯Έ ν”„λ‘œμ νŠΈ νŒŒμΌμ—μ„œ 이미 μ‚¬μš©μ€‘μΈ νŠΉμ • 포트λ₯Ό μ‚¬μš©ν•˜λ € ν• λ•Œ λ‚˜νƒ€λ‚˜λŠ” μ—λŸ¬μ΄λ‹€. 즉 address already in use :::5000이라면 '5000번 ν¬νŠΈκ°€ ν˜„μž¬ λ‹€λ₯Έ ν”„λ‘œμ„ΈμŠ€μ—μ„œ μ‚¬μš©μ€‘μ΄κΈ° λ•Œλ¬Έμ— ν•΄λ‹Ή 포트λ₯Ό μ‚¬μš©ν•˜λŠ” ν˜„μž¬ μ„œλΉ„μŠ€λ₯Ό μ‹œμž‘ν•  수 μ—†λ‹€λŠ” λœ»μ΄λ‹€.

보톡 μ΄λŸ΄λ•ŒλŠ” ꡬ동쀑인 터미널듀을 λ’€μ Έμ„œ λ™μΌν•œ 포트둜 가동쀑인 μ„œλ²„κ°€ μžˆλ‹€λ©΄ λ‘˜μ€‘ ν•˜λ‚˜λ₯Ό κΊΌμ£Όκ±°λ‚˜,ν•˜λ‚˜μ˜ 포트만 λ³€κ²½ν•΄μ£Όλ©΄ ν•΄κ²°λ˜λŠ” λ¬Έμ œμ˜€μ§€λ§Œ, 아무리 터미널을 뒀져봐도 5000번 포트둜 가동쀑인 μ„œλ²„λŠ” ν˜„μž¬ μž‘μ—…μ€‘μΈ ν”„λ‘œμ νŠΈ ν•˜λ‚˜λ°–μ— μ—†μ—ˆλ‹€.

Stack Overflow λ₯Ό μ°Ύμ•„λ³΄λ‹ˆ μ’…μ’… ν•΄λ‹Ή 포트λ₯Ό μ‚¬μš©ν•˜λ˜ Nodejs ν”„λ‘œμ„Έμ„œκ°€ λΉ„μ •μƒμ μœΌλ‘œ μ’…λ£Œλœ κ²½μš°μ—λ„ λ‚˜νƒ€λ‚  수 μžˆλ‹€κ³ ν•œλ‹€!


Im Full Stack Overflow

μš°μ„  μ„œλ²„λ₯Ό μ™„μ „νžˆ μ’…λ£Œν•œλ’€ 5000번 포트λ₯Ό μ‚¬μš©ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€λ₯Ό μ°Ύμ•„μ„œ κ°•μ œ μ’…λ£Œν•΄μ£ΌκΈ°λ‘œ ν–ˆλ‹€.
λ¦¬λˆ…μŠ€μ™€ λ§₯osμ—μ„œλŠ”ν„°λ―Έλ„μ—μ„œμ˜ lsof λͺ…λ Ήμ–΄λ₯Ό 톡해 ν”„λ‘œμ„ΈμŠ€λ₯Ό ν™•μΈν•˜κ³  μ’…λ£Œν• μˆ˜ μžˆλ‹€κ³ ν•œλ‹€. lsofλŠ” ν„°λ―Έλ„μ—μ„œ ν™œμ„±ν™”λœ ν”„λ‘œμ„ΈμŠ€ 리슀트λ₯Ό 좜λ ₯ν•΄μ£ΌλŠ” λͺ…령어이닀. -i μ˜΅μ…˜μ„ μ‚¬μš©ν•˜λ©΄ νŠΉμ • 포트λ₯Ό μ‚¬μš©μ€‘μΈ ν”„λ‘œμ„ΈμŠ€λ§Œμ„ 보여쀀닀고 ν•œλ‹€.

μ™Όμͺ½λΆ€ν„° ν”„λ‘œμ„ΈμŠ€ 이름, PID값을 확인할 수 μžˆλŠ”λ°, μ„œλ²„λ₯Ό μΌœμ Έμžˆμ§€ μ•ŠμŒμ—λ„ λΆˆκ΅¬ν•˜κ³ , 5000번 포트λ₯Ό μ°¨μ§€ν•˜κ³ μžˆλ‹€.
이제 터미널에 kill -9 (PIDκ°’) λͺ…λ Ήμ–΄λ₯Ό 톡해 ν”„λ‘œμ„ΈμŠ€λ₯Ό κ°•μ œ μ’…λ£Œν•΄λ³΄μž. '-9'λŠ” kill의 κ°•μ œ μ’…λ£Œ μ‹œκ·Έλ„μΈ 9λ²ˆμ„ μ‚¬μš©ν•œλ‹€λŠ” μ˜λ―ΈλΌκ³ ν•œλ‹€.

이제 5000번 ν¬νŠΈλŠ” 곡싀이 λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

이제 5000번 포트λ₯Ό μ •μƒμ μœΌλ‘œ μ΄μš©ν•  수 μžˆκ²Œλ˜μ—ˆλ‹€!

profile
Take me home~~~~

3개의 λŒ“κΈ€

comment-user-thumbnail
2021λ…„ 6μ›” 15일

μ•ˆλ…•ν•˜μ„Έμš” γ… γ…  저도 μœ μ‚¬ν•œ λ¬Έμ œκ°€ λ– μ„œ sudo lsof -i :443 ν•œ 후에 κ΄€λ ¨ pidλ₯Ό sudo kill -9 ~~~λ₯Ό 톡해 μ‚­μ œν–ˆλŠ”λ°
μƒˆλ‘œμš΄ pid둜 계속 μƒμ„±λ˜λ”λΌκ΅¬μš” γ… γ… 30λ²ˆμ •λ„ μ‚­μ œν–ˆλŠ”λ°λ„ 아직 λ‚¨μ•„μžˆλŠ”λ° μ–΄λ–»κ²Œ ν•΄κ²°ν•˜λŠ”μ§€ μ•„μ‹œλ‚˜μš”?

2개의 λ‹΅κΈ€