[SOLVED] Socket: bind failed, error: Address already in use(98)

After unity hangs I usually kill it with xkill. After removing Temp folder in project root and relaunch project there is an error message in console “Socket: bind failed, error: Address already in use(98)”

This forces me to restart system because after this error I can’t debug my game at all (Breakpoints not hit)
There was a thread Socket bind failed, error: Address already in use(98) but there is no solution
On issue tracker Unity Issue Tracker - Socket: bind failed. Error: Address already in use(48) when importing the project this issue is marked as non-reproducible

ps aux | grep unity gives me some unityhub and unity-editor processes. But killing them still has no effect.

Solution:

Hi @IC1
Do you use any custom way to start adb services?
If not, looks like it is related to the killing thing.
After killing, could you check(netstat or similar) if anything is still using the port?
At least for me, Unity uses 34999 (based on command which uses tcp:34999), so maybe that port is still “locked” by Unity after manual process kill.

Thank you for response

No, I use adb from official ubuntu repos but it doesn’t look like Android related issue

I checked netstat and there is no unity records at all. Do you use any arguments to find unity in list?

@IC1
Unfortuantely my knowledge about the subject is limited here :slight_smile:
I don’t know about other tricks to find the blocking process apart from what you have been doing.
The only thing I can suggest is to try to reproduce it and file a bug report.

As I understand the fact that Unity freezes for you is crucial here.
Few times Unity freezed/crashed for me but after another Unity(not whole PC) restart I didn’t encounter issues you see.
So maybe it is not that easy to reproduce.

I have never cleared “Temp” folder after crash, why do you do it?

Because broken cache interrupts unity launch. It’s just closes without any errors. Sorry for late answer I’ve just stucked into that problem in hope to find a solution and noticed you question

After a big research with ag, grep, find and so on in whole system i’ve found that unity creates a file with name like /tmp/.mount_UnityHDpVLGD. You cannot just remove it even with sudo. The solution is to cd there and execute lsof +D ./ | awk '{print $2}' | tail -n +2 | xargs kill -9 in that directory (Original: files - How to get over "device or resource busy"? - Unix & Linux Stack Exchange), but my approach is better lsof /tmp/.mount_UnityH*/* | awk 'FNR > 1 {print $2}' | uniq | xargs sudo kill -9

After that unity can recreate socket successfully and debugging works fine

wow … that is some solution, great you were able to fix it for you

Hmm, that seems like a headache. Could submit a bug for this? Seems like Unity should probably nuke that file on startup.