Debug session thread and socket leak fixed:
To reproduce the bug:
- Start a PHP debugging session
- Open the Debug View
- Select the PHP main thread
- Terminate the thread with the red square button
Bug explanation:
The debugging session uses a Java thread to listen on a
server socket on port 10001. This thread runs
PHPDBGProxy.PHPLoop.run and blocks in
ServerSocket.accept. It stays blocked until a debugger
engine connects to the port. If the session is
terminated before a debugger engine connects, the
PHPLoop thread and the server socket are leaked.
Relevance:
The server socket continues to sit on port 10001 which
means later sessions have to go to ports 10002, 10003
etc. This has caused a lot of problems because people
fail to get the configuration right the first time,
leak the thread and socket, try again and get a session
on port 10002, but continue with a
?DBGSESSID=1@host:10001. I think, but I'm not sure,
that this leads to the socket write error exception
that has been reported in the forums - so that problem
may be fixed with this patched (but then again may not be).
Bug fix:
- The UI thread forcibly unblocks the loop thread by
closing the server socket.
- The PHPDebugTarget.terminate method is now
synchronized and re-entrant, to eliminate a race
condition between the UI and loop threads.
Two more fixes below.
PHPDBGProxy.MapPath:
Threw StringIndexOutOfBoundsException
when the input string is shorter than the mapped prefix.
Patch fixes this by using the String.startsWith method.
PHPDBGProxy.pause:
Inserted check to prevent a null pointer exception