godot icon indicating copy to clipboard operation
godot copied to clipboard

Error listening on port 6007 after deploying once on Android and closing the game on the mobile device

Open lefavilla opened this issue 4 years ago • 28 comments

Godot version: 3.2.2 stable mono

Issue description: Everytime when I launch an android debug build with custom build enabled direct to my smartphone and/or virtual test device godot can no longer connect to port 6007 if I deploy a second time. Due to this I get no prints or debug informations.

On 2nd build also play button, webbuild and such builds won't produce any prints or debug informations with same error.

I have to restart my computer to get rid of the blocked port. If I launch direct to android again I have to restart again.

Error: "error listening on port 6007".

Even if I kill the pid sitting on this port the problem won't vanish.

Steps to reproduce: Build a project with custom build checked per direct deploy to any android device. Do it again and the error appears.

Minimal reproduction project: simple 2d scene with custom build checked for android.

lefavilla avatar Aug 31 '20 15:08 lefavilla

Error still not fixed. Changing remote port to 6008 removes the error but the debugger still gets disconnected for me, and then the last output is "Connection Taken".

ultramarinebicycle avatar Feb 16 '21 07:02 ultramarinebicycle

This may be fixed by https://github.com/godotengine/godot/pull/37067 if it's merged.

Calinou avatar Feb 16 '21 16:02 Calinou

Need to debug a custom build with an Android local notification plugin and hard to do that without the debugger working 😄 Fingers crossed.

ultramarinebicycle avatar Feb 17 '21 09:02 ultramarinebicycle

I also have this issue. Hoping it gets resolved with the PR above.

I have to restart my computer to get rid of the blocked port.

Signing out and in again gets rid of it as well.

MikaelMollberg avatar Mar 02 '21 19:03 MikaelMollberg

For the time being, you can edit the port directly in the editor settings. You don't need to sign in and out nor restart your machine. grafik

HaSa1002 avatar Mar 02 '21 20:03 HaSa1002

For the time being, you can edit the port directly in the editor settings. You don't need to sign in and out nor restart your machine.

Yeah you can iterate hundrets of ports and than you can down-iterate after restart... thats not realy a solution, thats a work around with risks.

lefavilla avatar Mar 03 '21 11:03 lefavilla

For the time being, you can edit the port directly in the editor settings. You don't need to sign in and out nor restart your machine.

Yeah you can iterate hundrets of ports and than you can down-iterate after restart... thats not realy a solution, thats a work around with risks.

@lefavilla That is indeed true. It was never meant as go-to solution. It is a workaround, yes, but a better one than restarting your computer. I only meant to give an easier workaround for people, who may not know the configurability of the debugger port. FYI the mentioned PR does excactly what you can do by hand, only that it provides better usability 😃

HaSa1002 avatar Mar 04 '21 20:03 HaSa1002

I'm still having this error as of 3.3.1

likeich avatar May 23 '21 07:05 likeich

AFAIK there is a fix in 3.4. (in the 3.x branch I used yesterday to compile the engine)

HaSa1002 avatar May 23 '21 10:05 HaSa1002

AFAIK there is a fix in 3.4. (in the 3.x branch I used yesterday to compile the engine)

Indeed, https://github.com/godotengine/godot/pull/37067 has been merged in the 3.x branch but hasn't been cherry-picked to the 3.3 branch so far. In the meantime, there is a workaround you can use with an editor plugin: https://github.com/godotengine/godot/pull/37067#issuecomment-665863474

Calinou avatar May 23 '21 12:05 Calinou

In 3.4.2 after one deploy to Android, I get this error:

" Remote debugger failed listening on port: 6007 Retrying on new port: 6008 Connection Taken"

but the debugger still doesn't connect on the new port.

NianoTT avatar Jan 23 '22 16:01 NianoTT

In 3.4.2 after one deploy to Android, I get this error:

" Remote debugger failed listening on port: 6007 Retrying on new port: 6008 Connection Taken"

but the debugger still doesn't connect on the new port.

Does this occur when running a project from two different editor instances on your own machine?

Calinou avatar Jan 23 '22 17:01 Calinou

Does this occur when running a project from two different editor instances on your own machine?

Happens with 1 or 2 instances.

However, I just noticed it only happens when "Use Custom Build" is enabled in Export (I'm using the Google Play Billing Plugin). When building the APK, I also get an error from Gradle that it could not reuse a stopped process or something like that (would need to record screen if more information is required as it only shows briefly).

NianoTT avatar Jan 23 '22 17:01 NianoTT

Also changing the port, like suggested above, does not fix it - debugger gives "Connection taken" and does not work, neither on further Android deploys nor any other ones, so after one custom build Android deploy the debugger is gone unless you restart the pc.

I hope this can be fixed, as it makes debugging almost impossible when using custom builds on Android, forcing you to having to restart your pc after every deploy.

NianoTT avatar Mar 02 '22 00:03 NianoTT

so after one custom build Android deploy the debugger is gone unless you restart the pc.

As a workaround, you can probably kill the debugger process using a task manager.

Calinou avatar Mar 02 '22 00:03 Calinou

so after one custom build Android deploy the debugger is gone unless you restart the pc.

As a workaround, you can probably kill the debugger process using a task manager.

I wanted to do that, but after killing every Godot process (which was not enough) I did not found any more that I could relate to it. Is the debugger a separate process in itself, if so what is it called?

NianoTT avatar Mar 02 '22 10:03 NianoTT

Is the debugger a separate process in itself, if so what is it called?

It may be an adb process or something like that.

Calinou avatar Mar 02 '22 17:03 Calinou

Killing adb doesn't free it up, andd I can't find any process that might be related to it...

NianoTT avatar Mar 03 '22 08:03 NianoTT

There are ways to check which software eats the port. If you use Windows, follow this guide: https://www.maketecheasier.com/check-ports-in-use-windows10/#:~:text=1%20How%20to%20Check%20for%20Ports%20in%20Use,app%20and%20want%20to%20have%20more%20control%20 For Linux distros: https://linuxize.com/post/check-listening-ports-linux/ For macOS: https://www.btaz.com/mac-os-x/find-the-process-listening-to-port-on-mac-os-x/

HaSa1002 avatar Mar 03 '22 14:03 HaSa1002

Also getting this on 3.4.2 stable. netstat showing some process using the port but I can't kill them. The only workaround so far that has worked for me is from here by setting remote host to 0:0:0:0:0:0:0:1 and the remote port to a different one in editor > editor setting > network https://godotforums.org/discussion/23142/port-6007-error-when-disconnecting-android-test-device

nickcyyt avatar Mar 07 '22 05:03 nickcyyt

hello ,I got this problem too. and have to restart computer to fix it. maybe it is because I first open AndroidStudio and run godot ,and Androidstudio somehow block godot from communicating the app

lcfzblcfzb avatar May 03 '22 04:05 lcfzblcfzb

I also started to get this error when i run debug on android over usb (v 3.4.3). "Remote debugger failed listening on port: 6007 Retrying on new port: 6008"

It starts to appear after ending of the first debugging session:

  1. run debug for the first time: everything is ok, breakpoints work, I can iterate over the functions.
  2. stop the program in android (swipe it in recent apps)
  3. run debug again:
    • start to get error ""Remote debugger failed listening on port: 6007..."
    • debug is not available, I don't get any output from the app in the Output window
    • as I can see, breakpoints work (because program freezes if I set any breakpoint), but I have no control over the debugging process, because editor didn't connect to the running app.

My workaround is the following (killing the gradle daemon):

  • I run cmd in separate window
  • execute the command WMIC PROCESS where "Name like 'java%' AND CommandLine like '%GradleDaemon%'" Call Terminate
  • after this debug stars to work but only the first time.
  • after ending of debugging session, I have to kill gradle daemon again.

🤷‍♂️

yurii-sio2 avatar May 03 '22 07:05 yurii-sio2

Reply to myself: after project reload remote debugger on android started to work normaly.

yurii-sio2 avatar May 03 '22 13:05 yurii-sio2

I've just hit this exact problem on Godot 3.5 Stable (downloaded from official Godot site). Have "custom build" switched on for GodotGooglePlayBilling. Killing Java.exe allows the console output to come back, but breakpoints still don't work. Restarting Godot makes no difference to breakpoints.

wombatwingdings avatar Aug 26 '22 18:08 wombatwingdings

I can confirm this is still happening with Godot 3.5 stable, custom build. I can use the command yurii-sio2 posted above (https://github.com/godotengine/godot/issues/41650#issuecomment-1115806561) to get the debugger working again

When I turn off the custom build option, the debugger correctly disconnects.

bspear8 avatar Oct 08 '22 23:10 bspear8

Still present in 3.5.2 Stable, Custom build on, using OpenXR for a VR project, the solution provided by yurii-sio2 works, but is quite lame to wait an extended amount of time for it do it's initial build. (ontop of already waiting for the project to reload; you all know the process)

DefaultHeathen avatar Mar 09 '23 00:03 DefaultHeathen

Another workaround I found: right after the first deploy to android, change the remote debug port in editor setting to be something different then current port and current port+1 (so if its 6007 change to 6009). Subsequent deploys will work as expected. This is on 3.5.1

NianoTT avatar Mar 09 '23 13:03 NianoTT

BTW this is probably fixed incidentally in Godot 4.0.

What likely happens here is:

  1. Your start a remote debugging process over port 6007, which is the default.
  2. When you terminate the game on the mobile device, Godot doesn't know about it, so it doesn't release port 6007.
  3. When the port is busy, it tries to use the next port, 6008.
  4. But in 3.x, that port is occupied by the GDScript LSP. This was changed in 4.0, where the GDScript LSP now uses port 6006 instead. So 6008 is free and it should work fine.

So @NanitesNanites' workaround to change Godot's default port should indeed work, provided that the N+1 port is not already taken by another process on your system.

The proper fix for this here though, is that at (2.), Godot should someone figure out that the process was terminated and make sure the port is released.

akien-mga avatar Mar 09 '23 14:03 akien-mga

The comment by @akien-mga was the key for me. I've changed the debug port to 7000 in Editor>Settings>Debug and now it's working fine.

oscar-1 avatar Mar 18 '23 19:03 oscar-1

I've changed the debug port to 7000 in Editor>Settings>Debug and now it's working fine.

You mean Editor->Settings->Language Server? As changing this actually "fixes" it for good, without having to do something else ever again. You still get the warning that the port was taken every time but it automatically changes to the next one and works.

@akien-mga worth making a PR for 3.x to change the LSP port? It's not a full fix but a workaround, but it works and should remove a lot of annoyance from those who don't know about the manual workarounds.

NianoTT avatar Apr 16 '23 12:04 NianoTT