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

[NETBEANS-6177] Fix an issue the stop command is not sent #3549

Merged
merged 1 commit into from Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions php/php.dbgp/src/org/netbeans/modules/php/dbgp/DebugSession.java
Expand Up @@ -78,6 +78,7 @@ public class DebugSession extends SingleThread {
private AtomicReference<DebuggerEngine> engine;
private IDESessionBridge myBridge;
private AtomicReference<String> myFileName;
private volatile boolean canceled;

DebugSession(DebuggerOptions options, BackendLauncher backendLauncher) {
commands = new LinkedList<>();
Expand Down Expand Up @@ -124,6 +125,14 @@ public void run() {
} catch (Throwable e) {
log(e, Level.SEVERE);
}
if (canceled) {
synchronized (commands) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me. However, the threading in this class is not documented and is not clear to me - I can see no synchronization of commands in preprocess() method, for example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (commands.isEmpty()) {
detachRequest.set(true);
stop();
}
}
}
}
} finally {
postprocess();
Expand All @@ -133,7 +142,9 @@ public void run() {
private void preprocess() {
detachRequest.set(false);
stopRequest.set(false);
commands.clear();
synchronized (commands) {
commands.clear();
}
sessionId.set(null);
myBridge = new IDESessionBridge();
myFileName = new AtomicReference<>();
Expand Down Expand Up @@ -325,14 +336,14 @@ private void printing146558(Thread currentThread) {

@Override
public boolean cancel() {
// NETBEANS-5080 detach the request
// NETBEANS-5080 request cancellation
// startProcessing() may be called via other ways
// e.g. via command line: nc -vz localhost 9003(debugger port)
// First of all, get the socket after the above command is run
// See: Socket sessionSocket = myServer.accept(); in ServerThread.run()
// Then, invokeLater.get() is called in startProcessing()
// Finally, infinite loop occurs in run() becuase do not still receive anything
detachRequest.set(true);
canceled = true;
return true;
}

Expand Down
Expand Up @@ -101,11 +101,6 @@ synchronized Session startSession(SessionId id, DebuggerOptions options, Callabl

public synchronized void stopSession(Session session) {
SessionId id = session.lookupFirst(null, SessionId.class);
// NETBEANS-5080 detach the request of the debug session to finish the task
DebugSession debugSession = session.lookupFirst(null, DebugSession.class);
if (debugSession != null) {
debugSession.cancel();
}
DebugSession debSess = getSession(id);
if (debSess != null) {
debSess.stopSession();
Expand All @@ -122,6 +117,11 @@ public static void stopEngines(Session session) {
}
SessionManager.closeServerThread(session);
resetBreakpoints();
// NETBEANS-5080 request cancellation to finish the task
DebugSession debugSession = session.lookupFirst(null, DebugSession.class);
if (debugSession != null) {
debugSession.cancel();
}
}

public static SessionId getSessionId(Project project) {
Expand Down