Could not run the sketch. (ERROR: transport error 202: bind failed:)

Hello folks!

I occasionally encounter the following error when running sketches:

  • Could not run the sketch:
    ERROR: transport error 202: bind failed: Permission denied

  • Text copied from console (in blue in console):

ERROR: transport error 202: bind failed: Permission denied
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [s\src\jdk.jdwp.agent\share\native\libjdwp\debugInit.c:734]
Using startup command: D:\Program_Portable\Processing-4.4.10\app\resources\jdk\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=8053,server=y,suspend=y,quiet=y -Djna.nosys=true -Djava.library.path=;D:\Program_Portable\Processing-4.4.10\app\resources\core\library;D:\Program_Portable\Processing-4.4.10;
*** ...The remaining paths removed... ***

This issue with any sketch I run and is not directly related to the code.

Here’s what I’ve observed:

  • It happens occasionally and does not repeat for the current code in use.
  • I’m able to Save the file before the IDE locks up.
  • If I wait long enough, sometimes the IDE resumes on its own.
  • In some cases, I have to use Windows Task Manager to End Task.

Has anyone experienced something similar or have any suggestions for resolving this?

Thanks in advance for any help!

:)

So what is happening here is that Processing is trying to open a port for the debug connection on a port between 8000 - 9000:

int port = 8000 + (int) (Math.random() * 1000);

I suspect you are running some kind of service (at 8080 perhaps) locally that Processing will occasionally (1 in 1000) match with that service. There is no check if this port is in use and the program will hang

1 Like

Hello @stefterv

Thanks so much for your support!

Tracked down the services on my W10 PC currently bound to these ports:

C:\Users\GLV>netstat -ano | find ":8307"
  TCP    127.0.0.1:8307         0.0.0.0:0              LISTENING       5616
  TCP    [::1]:8307             [::]:0                 LISTENING       5616

C:\Users\GLV>tasklist /FI "PID eq 5616"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
vmware-hostd.exe              5616 Services                   0     30,296 K

C:\Users\GLV>netstat -ano | find ":8082"
  TCP    0.0.0.0:8082           0.0.0.0:0              LISTENING       5640

C:\Users\GLV>tasklist /FI "PID eq 5640"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
RNADiagnosticsSrv.exe         5640 Services                   0     14,304 K

C:\Users\GLV>netstat -ano | find ":8884"
  TCP    127.0.0.1:8884         0.0.0.0:0              LISTENING       4

C:\Users\GLV>tasklist /FI "PID eq 4"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System                           4 Services                   0      3,240 K

These are fixed ports in use; I can’t change system ones. Not sure about others.

I am not adding more to your plate at this time.

Could the IDE could be modified to store a preferred debug port in preferences.txt and read it at startup?
Or check for ports before binding?

I would like to tackle this!
Point me in the right direction in the Processing source code.
I will do the coding part.

Mechanics:

  1. Add a new preference key, e.g., debug.port=XXXX.
  2. On startup, read the key and attempt to bind to that port.
  3. If it’s in use, either choose another or prompt the user.

Or:

  1. Check ports in use and try another one.

This would allow a consistent, user-defined debug port and avoid random collisions.
It would require modifying the IDE’s source and rebuilding it.

:)

1 Like

Hey @glv That’s a great idea

This is where the port is selected. You can read a key from the preferences with Preferences.getInt()

2 Likes

Hello,

Adding to my toolbox and sharing.

Tests for ports in use in range 8000 to 9000:

import processing.net.*;

//import java.net.ServerSocket; 
//import java.io.IOException

void setup() 
  {     
  // Uncomment the method you want to run
  
  portScan_2();  // Using ServerSocket directly
  println();
  delay(3000);  // 3s delay to see output.
                // Don't like to use delay() but ok here.
  portScan_0();  // Processing server

  println("Done scanning.");
  }
  
void draw()
  {
  }
  
//**************************************************************************************************
// Method 0: Using Processing Server
// Produces SocketException messages when stopping the server

void portScan_0()
  { 
  for (int port = 8000; port <= 9000; port++) 
    {  
    try 
      {
      Server s = new Server(this, port);
      //println("Opened port: " + port);
      //println(s);
      s.stop(); // immediately free it
      } 
    catch (RuntimeException e) 
      {
      //if (e.getMessage() != null && e.getMessage().contains("BindException"))
      if (e.getMessage().contains("BindException")) 
        {
        println("Port in use: " + port);
        } 
      else 
        {
        println("Error on port " + port + ": " + e.getMessage());
        }
      }  
    }
  }    

//**************************************************************************************************
// Method 2: Using ServerSocket directly
// Does NOT produce SocketException messages

void portScan_2()
  {
  for (int port = 8000; port <= 9000; port++) 
    {
    try (java.net.ServerSocket s1 = new java.net.ServerSocket(port)) 
      {
      //println("Port free: " + port);
      } 
    catch (java.net.BindException e) 
      {
      println("Port in use: " + port);
      } 
    catch (IOException e) 
      {
      // ignore other IO errors
      }
    }  
  }  

:)