Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lefavilla opened this issue Aug 31, 2020 · 35 comments

Comments

@lefavilla
Copy link

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.

@ultramarinebicycle
Copy link

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".

@Calinou
Copy link
Member

Calinou commented Feb 16, 2021

This may be fixed by #37067 if it's merged.

@Calinou Calinou added the bug label Feb 16, 2021
@ultramarinebicycle
Copy link

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

@MikaelMollberg
Copy link

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.

@HaSa1002
Copy link
Contributor

HaSa1002 commented Mar 2, 2021

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

@lefavilla
Copy link
Author

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.

@HaSa1002
Copy link
Contributor

HaSa1002 commented Mar 4, 2021

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 😃

@likeich
Copy link
Contributor

likeich commented May 23, 2021

I'm still having this error as of 3.3.1

@HaSa1002
Copy link
Contributor

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

@Calinou
Copy link
Member

Calinou commented May 23, 2021

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

Indeed, #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: #37067 (comment)

@NianoTT
Copy link

NianoTT commented Jan 23, 2022

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.

@Calinou
Copy link
Member

Calinou commented Jan 23, 2022

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?

@NianoTT
Copy link

NianoTT commented Jan 23, 2022

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
Copy link

NianoTT commented Mar 2, 2022

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.

@Calinou
Copy link
Member

Calinou commented Mar 2, 2022

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.

@NianoTT
Copy link

NianoTT commented Mar 2, 2022

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?

@Calinou
Copy link
Member

Calinou commented Mar 2, 2022

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

It may be an adb process or something like that.

@NianoTT
Copy link

NianoTT commented Mar 3, 2022

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

@nickcyyt
Copy link

nickcyyt commented Mar 7, 2022

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

@lcfzblcfzb
Copy link

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

@yurii-sio2
Copy link

yurii-sio2 commented May 3, 2022

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
Copy link

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

@wombatwingdings
Copy link

wombatwingdings commented Aug 26, 2022

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.

@bspear8
Copy link

bspear8 commented Oct 8, 2022

I can confirm this is still happening with Godot 3.5 stable, custom build. I can use the command yurii-sio2 posted above (#41650 (comment)) to get the debugger working again

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

@DefaultHeathen
Copy link

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)

@akien-mga akien-mga changed the title Error listening on port 6007 Error listening on port 6007 after deploying once on Android and closing the game on the mobile device Mar 9, 2023
@NianoTT
Copy link

NianoTT commented Mar 9, 2023

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

@akien-mga
Copy link
Member

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.

@oscar-1
Copy link

oscar-1 commented Mar 18, 2023

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.

@NianoTT
Copy link

NianoTT commented Apr 16, 2023

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.

@oscar-1
Copy link

oscar-1 commented Apr 20, 2023

I mean Remote Port

@akien-mga
Copy link
Member

@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.

This will break the LSP. We did that change in 4.0 and it broke plugins, which now don't know whether they should use the Godot 3.x port or the Godot 4.0 port. The situation will smooth itself out over time as more users move to Godot 4+ but we shouldn't break compatibility on Godot 3.

@rockgem
Copy link

rockgem commented Jun 26, 2023

I can confirm this still happens with Godot 4.0.2 build with this same exact problem :

i have enabled the GodotPlayBilling plugin

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.

🤷‍♂️

edit:

the workaround i have found is to go to task manager and find Java.exe and ending the process. it supposedly stops the gradle process and closes the port along with it.

@DefaultHeathen
Copy link

DefaultHeathen commented Jul 14, 2023

Godot 4.1 Stable; Quest 2 debug export

No longer getting the "error listening on..." but the symptom persists with the changing of the remote port fixing the issue for regular output and debugging. The Quest [2] however still freezes up as if it's still connected, just no output from the console.

May be a completely different issue now or not, not sure; wanted to mention it tho.

Edit: I got the console to run normally without messing with the remote port, sometimes. I think it's something on my end. Glad no one noticed >.>

@ArchLinus
Copy link

Found some more information on this issue at #82764 (comment).

There are two different issues going on here:

  1. Windows is not cleaning up the port after Godot exits. Still not entirely sure why this happens, but I suspect godot never explicity closed the port and with the child processes still running prevents Windows from cleaning the ports.

https://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process

  1. The android export plugin just uses the editor remote port setting and doesn't account for retry attempts. This should be an easy fix. This will allow debugging but won't fix the underlying port issue.
Error EditorExportPlatformAndroid::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
    ...
    // This should be changed to the port used by EditorDebuggerServerTCP
    int dbg_port = EDITOR_GET("network/debug/remote_port");
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests