Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 390019 - Termination event isn't sent when output goes through terminal
Summary: Termination event isn't sent when output goes through terminal
Status: RESOLVED WORKSFORME
Alias: None
Product: TCF
Classification: Tools
Component: Target (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Uwe Stieber CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-20 10:03 EDT by Anna Dushistova CLA
Modified: 2012-09-25 10:21 EDT (History)
1 user (show)

See Also:


Attachments
logs (1.82 MB, application/octet-stream)
2012-09-23 10:53 EDT, Anna Dushistova CLA
no flags Details
code (171.65 KB, application/octet-stream)
2012-09-24 12:12 EDT, Anna Dushistova CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anna Dushistova CLA 2012-09-20 10:03:49 EDT
I've registered the following listener in my code:

       public void eventFired(EventObject event) {
                if (event instanceof ProcessStateChangeEvent) {
                        ProcessStateChangeEvent pscEvent = (ProcessStateChangeEvent) event;
                        System.out.println(pscEvent.toString());
                        if (pscEvent.getEventId().equals(
                                        ProcessStateChangeEvent.EVENT_PROCESS_TERMINATED)) {
                                if ((pscEvent.getSource() instanceof ProcessContext)
                                                && ((ProcessContext) pscEvent.getSource()).getID()
                                                                .equals(context.getID())) {
                                        exitValue = pscEvent.getExitCode();
                                        terminated = true;
                                        fireTerminateEvent();
                                }
                        }
                }

However, in my console the only event I am getting is the process creation event I am generating myself. Also, terminal window stays active forever.
Comment 1 Uwe Stieber CLA 2012-09-20 10:11:36 EDT
Can you log the TCF communication for this case? One way of doing this is to enable "Enable logging" within the preferences (Window > Preferences > Target Explorer > Logging) and ZIP and attach the content of ${workspace_loc}/.metadata/.plugins/org.eclipse.tcf.te.tcf.log.core/.logs.

The questions is if we get the terminated event from the agent.
Comment 2 Anna Dushistova CLA 2012-09-20 17:46:40 EDT
Here is the log from the agent's command line(started as  obj/GNU/Linux/i686/Debug/agent  -l0x7C -L-):
===================================================================                                           
TCF 44:02.147: Starting channel 0x8100848 TCP:127.0.0.1:49402                                                 
TCF 44:02.147: channel server connecting                                                                      
TCF 44:02.175: Peer TCP:127.0.0.1:49402: Event: E Locator Hello ...                                           
TCF 44:02.175: channel server connected, remote services:                                                     
TCF 44:02.175:   Diagnostics                                                                                  
TCF 44:02.175:   Locator                                                                                      
TCF 44:02.175:   ZeroCopy                                                                                     
TCF 44:02.212: Peer TCP:127.0.0.1:49402: Command: C 0 FileSystem stat ...                                     
TCF 44:02.223: Peer TCP:127.0.0.1:49402: Command: C 1 FileSystem open ...                                     
TCF 44:02.244: Peer TCP:127.0.0.1:49402: Command: C 2 FileSystem write ...                                    
TCF 44:02.296: Peer TCP:127.0.0.1:49402: Command: C 3 FileSystem write ...
TCF 44:02.303: Peer TCP:127.0.0.1:49402: Command: C 4 FileSystem write ...
TCF 44:02.310: Peer TCP:127.0.0.1:49402: Command: C 5 FileSystem fstat ...
TCF 44:02.315: Peer TCP:127.0.0.1:49402: Command: C 6 FileSystem fsetstat ...
TCF 44:02.318: Peer TCP:127.0.0.1:49402: Command: C 7 FileSystem close ...
TCF 44:02.356: Socket is shutdown by remote peer, channel 0x8100848 TCP:127.0.0.1:49402
TCF 44:02.356: Closing channel 0x8100848 TCP:127.0.0.1:49402
TCF 44:02.356: channel 0x8100848 disconnected
TCF 44:02.439: Deleting channel 0x8100848
TCF 44:02.499: Starting channel 0x8100848 TCP:127.0.0.1:49403
TCF 44:02.499: channel server connecting
TCF 44:02.590: Peer TCP:127.0.0.1:49403: Event: E Locator Hello ...
TCF 44:02.590: channel server connected, remote services:
TCF 44:02.590:   Diagnostics
TCF 44:02.590:   Locator
TCF 44:02.590:   ZeroCopy
TCF 44:02.644: Peer TCP:127.0.0.1:49403: Command: C 8 Streams subscribe ...
TCF 44:02.760: Peer TCP:127.0.0.1:49403: Command: C 9 ProcessesV1 getEnvironment ...
TCF 44:02.842: Peer TCP:127.0.0.1:49403: Command: C 10 ProcessesV1 start ...
TCF 44:02.978: waitpid: add pid 5516
TCF 44:03.069: waitpid: pid 5516 status 0, error 0
TCF 44:03.069: waitpid: pid 5516 exited, exit code 0
TCF 44:03.069: event: ctx not found, pid 5516, exit status 0, term signal 0
TCF 44:03.070: Peer TCP:127.0.0.1:49403: Command: C 11 Streams read ...
TCF 44:03.111: Peer TCP:127.0.0.1:49403: Command: C 12 Streams read ...
TCF 44:03.114: Peer TCP:127.0.0.1:49403: Command: C 13 Streams disconnect ...
TCF 44:03.141: Peer TCP:127.0.0.1:49403: Command: C 14 Streams unsubscribe ...
TCF 44:03.144: Socket is shutdown by remote peer, channel 0x8100848 TCP:127.0.0.1:49403
TCF 44:03.144: Closing channel 0x8100848 TCP:127.0.0.1:49403
TCF 44:03.144: Stream is left connected by client: VS0
TCF 44:03.144: channel 0x8100848 disconnected
TCF 44:03.146: Deleting channel 0x8100848
======================================================================
Comment 3 Anna Dushistova CLA 2012-09-21 08:14:21 EDT
After launching my test run launch about 10 times in a row, I have to correct my statement: sometimes termination event gets sent and the terminal window becomes inactive as expected. However, it happened only once or twice. Also sometimes I see no output(in console there is a "Failed to read the output" message).
Comment 4 Anna Dushistova CLA 2012-09-21 09:10:54 EDT
I am experiencing the same behavior with the TCF run launcher.
Comment 5 Uwe Stieber CLA 2012-09-21 11:57:54 EDT
For me, this looks like an issue on the agent side. Probably the process is so short living that the agent cannot intercept the process properly before it dies again. Can you add a sleep at the end of the launched process (if it is one you have build by yourself)?

And you may enable tracing for the processes listener. See the .options file in o.e.tcf.te.tcf.processes.core. It will print the tracing information to stdout. If  you see "exited" called for the launched process ID and the terminal is still active, than this is something we can fix on the TE side. If you don't see "exited" called, than this is on the agent side.
Comment 6 Eugene Tarassov CLA 2012-09-21 19:16:01 EDT
I tried to reproduce it on Fedora 15 and OpenSUSE 11. The agent appears to generate correct event messages, including "ProcessesV1 exited".

BTW, agent's log (-l option) is not a right way to see TCF channel traffic. In particular, -l log does not say anything about outgoing messages. To see all messages, you need to use a protocol logger, like TCF Trace view in Eclipse.
Comment 7 Uwe Stieber CLA 2012-09-22 09:34:19 EDT
It works for me too on openSUSE 12.1.

15:27:43.721: ---> C 3 Streams subscribe "ProcessesV1"
15:27:43.723: <--- R 3
15:27:43.804: ---> C 4 ProcessesV1 getEnvironment
15:27:43.805: <--- R 4 [...]
15:27:43.809: ---> C 5 ProcessesV1 start "/home/uwe/tmp" "/home/uwe/tmp/HelloWorld" ["/home/uwe/tmp/HelloWorld"] [...] {"StopAtEntry":false,"StopAtMain":false,"UseTerminal":true,"Attach":false,"AttachChildren":false}
15:27:43.811: <--- E Streams created "ProcessesV1" "VS0" "P9240"
15:27:43.813: <--- E Streams created "ProcessesV1" "VS1" "P9240"
15:27:43.813: <--- R 5 {"Name":"[HelloWorld]","CanTerminate":true,"StdInID":"VS0","StdOutID":"VS1","ID":"P9240"}
15:27:43.818: <--- E Processes exited "P9240" 0
15:27:43.818: <--- E ProcessesV1 exited "P9240" 0
15:27:43.819: <--- E Processes exited "P9240" 0
15:27:43.820: <--- E ProcessesV1 exited "P9240" 0
# 2012-09-22 15:27:43.827: Closed channel 7e5f1c5e (error=null)
15:27:43.828: ---> C 6 Streams read "VS1" 1024
15:27:43.828: <--- R 6 (13)Hello World
  0 true
15:27:43.836: ---> C 7 Streams disconnect "VS1"
15:27:43.840: <--- E Streams disposed "ProcessesV1" "VS1"
15:27:43.841: <--- R 7
15:27:43.843: ---> C 8 Streams unsubscribe "ProcessesV1"
15:27:43.843: <--- R 8

Anna, can you enable logging as described in my first comment (Comment #1)? Attach the generated log to the bugzilla so we can have a look.
Comment 8 Anna Dushistova CLA 2012-09-23 10:53:35 EDT
Created attachment 221387 [details]
logs

After I pulled the latest from master, I fail to get any output in the terminal.
Here is my console log:
!ENTRY org.eclipse.tcf.te.tcf.processes.core 4 0 2012-09-23 18:42:57.170
!MESSAGE Failed to read data from stream with id 'VS13'.

Possible Cause:
Channel is closed
!STACK 0
java.lang.Exception: Channel is closed
	at org.eclipse.tcf.util.TCFTask$4.run(TCFTask.java:97)
	at org.eclipse.tcf.EventQueue.run(EventQueue.java:95)
	at java.lang.Thread.run(Thread.java:619)

!ENTRY org.eclipse.tcf.te.tcf.core 1 0 2012-09-23 18:42:57.184
!MESSAGE org.eclipse.tcf.core.ChannelTCP@104ee8: Channel closed. ; Possibly caused by: null
ChannelStateChangeListener at trace/channelStateChangeListener (Mode 0)
	ChannelStateChangeListener.stateChanged( org.eclipse.tcf.core.ChannelTCP@104ee8, CLOSED )
ChannelTraceListener at trace/channelTraceListener (Mode 0)
	TraceListener.onChannelClosed ( java.lang.NullPointerException )
ChannelManager at trace/channelManager (Mode 0)
	Request to close channel. Target id = TCP:127.0.0.1:1534
ChannelManager at trace/channelManager (Mode 0)
	Closed channel. Target id = TCP:127.0.0.1:1534
Comment 9 Uwe Stieber CLA 2012-09-24 04:07:34 EDT
In case you run it from a PDE environment, can you set a Java exception breakpoint for "NullPointerException" before you launch the process please? Send me the stacktrace and I'll take care of the NPE.
Comment 10 Anna Dushistova CLA 2012-09-24 11:56:49 EDT
Here is the stack:
Daemon Thread [TCF Event Dispatcher] (Suspended (exception NullPointerException))	
	TERunProcess.eventFired(EventObject) line: 161	
	EventManager$FireRunnable.run() line: 65	
	EventManager.fireEvent(EventObject) line: 344	
	ProcessProcessesListener.exited(String, int) line: 113	
	ProcessesProxy$1.event(String, byte[]) line: 128	
	ChannelTCP(AbstractChannel).handleInput(AbstractChannel$Message) line: 964	
	AbstractChannel.access$0(AbstractChannel, AbstractChannel$Message) line: 852	
	AbstractChannel$1$1.run() line: 254	
	EventQueue.run() line: 95	
	Thread.run() line: 619	

And I'll attach the code.
Comment 11 Anna Dushistova CLA 2012-09-24 12:12:26 EDT
Created attachment 221423 [details]
code
Comment 12 Anna Dushistova CLA 2012-09-25 10:21:12 EDT
Works for me now after replacing waiting for callback with listening for process creation event as Uwe suggested.