Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365770

Summary: Race condition in IOConsolePartitioner causes console output to be lost
Product: [Eclipse Project] Platform Reporter: Petar Petrov <petar.petrov>
Component: DebugAssignee: Paul Pazderski <paul-eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dh_tue, paul-eclipse, petar.petrov, sarika.sinha
Version: 3.7   
Target Milestone: 4.15 M3   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/155654
https://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=1cf22e3c35e548b84bd22a7341b4ea06e97804b3
Whiteboard: 4.15 M2
Bug Depends on:    
Bug Blocks: 553348    
Attachments:
Description Flags
Plugin to test race condition none

Description Petar Petrov CLA 2011-12-06 12:04:05 EST
Build Identifier: 20110615-0604

In IOConsolePartitioner there are two jobs - QueueProcessingJob and TrimJob. Although they cannot run simultaneously, there is no guarantee about the order in which they'll run. 
This may cause corrupted console output for clients of MessageConsole in the case where in same thread first there is a call to MessageConsole.clearConsole() and immediately after that several calls to println() on the message stream acquired from the console. In this case there the job for clearing the console may run after the job for processing the message stream, thus loosing lines.

Reproducible: Always
Comment 1 Paul Pazderski CLA 2019-08-30 17:26:51 EDT
This is still an issue. I have an idea how to fix it but first want to merge my other pending console changes or I conflict with myself.
Comment 2 Sarika Sinha CLA 2020-01-06 00:06:06 EST
Moved to M3, please change if you have some other plans.
Comment 3 Paul Pazderski CLA 2020-01-09 16:10:09 EST
*** Bug 323816 has been marked as a duplicate of this bug. ***
Comment 4 Eclipse Genie CLA 2020-01-11 17:38:37 EST
New Gerrit change created: https://git.eclipse.org/r/155654
Comment 5 Paul Pazderski CLA 2020-01-11 17:39:03 EST
Apart from the reported situation with print after clear and the later printed content is falsely cleared the reversed situation is also possible. It is just less useful but also possible that a print immediately followed by clear still shows the printed content in console.

If a user does the following in a single thread:
  outStream.print("First");
  console.clearConsole();
  outStream.print("Second");
he can expect to see only "Second" in console and after this change it should be the case.
Comment 6 Paul Pazderski CLA 2020-01-13 16:34:07 EST
Created attachment 281477 [details]
Plugin to test race condition

I made a small plugin for verification. It adds a test console (ClearConsole) and a test button/icon in Console view (eclipse icon). In fact the button is added and usable on each MessageConsole.

The button execute similar code as in my example above.
Print "must be cleared"
Clear
Print "must be shown"

Before fix with race condition described in comment 0 the actual result is an empty console. In the other race condition I added it shows both strings. In fixed console only the second string is visible.
Comment 8 Paul Pazderski CLA 2020-01-17 15:24:32 EST
(In reply to Paul Pazderski from comment #1)
> This is still an issue. I have an idea how to fix it but first want to merge
> my other pending console changes or I conflict with myself.

Old implementation set next trim offset to -1 and the trim job removes all if offset is -1. The idea and fix is to use the current document length when clear is called as trim offset. This way content added after clear but before trim is not cleared anymore.