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

Bug 488906

Summary: Error running lint because the tern server is not started
Product: [ECD] Orion Reporter: Olivier Thomann <Olivier_Thomann>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: curtis.windatt.public, Michael_Rennie, steve_northover
Version: 11.0   
Target Milestone: 12.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Updated patch
none
debug output
none
proposed fix
none
updated fix none

Description Olivier Thomann CLA 2016-03-02 17:59:52 EST
On beta3, this is visible only if the debugger is not started.

1) get minesweeper-objects
2) make sure there is a .tern-project file
{
 "plugins": {},
 "libs": ["ecma5"],
 "ecmaVersion": 5,
 "loadEagerly": [
  "public/index.html"
 ]
}
3) click on main.js
You can see errors and warnings properly reported.
4) Refresh the page.
5) Sometimes you get an error saying the ESLint failed to validate the file because the tern server has not been started.

I need to see how it is possible that the server is not started when the lint request that comes from the validator is run. The change for bug 488530 was to enforce that the tern server is restarted when the .tern-project file is added. Any requests made before the server is started were supposed to be queued. Now it looks like the lint request is run when no tern server is available.
Comment 1 Michael Rennie CLA 2016-03-03 13:03:29 EST
I pushed some dark-launched tracing to master so we can record what is happening:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=8a545700ef6c63d0b6d0b42fc85d502c08d40c10
Comment 2 Michael Rennie CLA 2016-03-03 13:05:05 EST
To activate the tracing, open the dev console and enter the following:

localStorage.js_message_trace="true"

hit enter, close the dev tools, and reload the page.

Reopen the dev tools after the page loads and you see the error - should have the trace in the console.
Comment 3 Olivier Thomann CLA 2016-03-03 14:38:24 EST
Created attachment 260069 [details]
Updated patch

Patch from Michael
Comment 4 Olivier Thomann CLA 2016-03-03 15:20:08 EST
After testing a build that contains the fix on beta3, the problem seems to be gone.
Closing as fixed.
Comment 5 Steve Northover CLA 2016-03-16 11:18:34 EDT
Still happening to me.  Will debug with Olivier.
Comment 6 Steve Northover CLA 2016-03-16 11:20:42 EDT
Created attachment 260350 [details]
debug output
Comment 7 Michael Rennie CLA 2016-03-16 11:49:56 EDT
Here is a simplified trace:

postMessage (0) - MESSAGE QUEUED: {"request":"lint"}}
worker_ready (0): {"request":"worker_ready"}
postMessage (1) - SENT {"request":"start_server","args":{"initial":true},"messageID":0}
server_ready (1): {"request":"start_server","state":"server_ready","messageID":0}
clearing MESSAGE queue: {"request":"lint"}
postMessage (2) - SENT {"request":"lint"}
postMessage (3) - SENT {"request":"start_server","args":{"options":{"libs":["ecma5"],"ecmaVersion":5,"loadEagerly":["/file/snorthov-OrionContent/minesweeper-objects/public/index.html"]}},"messageID":2}
server_ready (3): {"request":"start_server","state":"server_ready","messageID":2}
postMessage (3) - SENT {"request":"read"}
postMessage (3) - SENT {"request":"read"}
postMessage (3) - SENT {"request":"read"}
postMessage (3) - SENT {"request":"read"}

The initial start up is flushing the message queue before the tern-project file is being used.
Comment 8 Michael Rennie CLA 2016-03-16 11:56:55 EDT
I think we need to get rid of the 'initial' start up and have the ternProjectManager always be the only thing that requests server starts.

So rather than having a default that is sent when the JS bundle loads (the root problem here) now start up requests will be sent until the manager loads and asks for one. The only thing we would need to change would be to remove the initial junk (and checks) from javaScriptPlugin.js and add a condition in the manager that when we don;t have a .tern-project file, request a default start up
Comment 9 Michael Rennie CLA 2016-03-16 16:06:28 EDT
Created attachment 260363 [details]
proposed fix

The patch changes how the Tern server is started - moving all the logic to the tern project manager. With this patch I only ever get one start_server request, regardless of it being initial startup, or a project switch. There is no more "plugin load start up" request being done.
Comment 10 Michael Rennie CLA 2016-03-16 16:34:20 EDT
Created attachment 260364 [details]
updated fix

Same fix as the previous patch, but updates the tracing to get rid of the excessive JSON output that makes it almost impossible to understand whats happening...
Comment 11 Michael Rennie CLA 2016-03-16 17:02:50 EDT
I pushed the second patch to:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=68588f30d24d6411ba03f48d58d7f0143e58bcec

after Olivier helped confirm the start up sequence was correct.

I'll leave this open until we get a few tracings from beta3.
Comment 12 Michael Rennie CLA 2016-03-16 18:00:36 EDT
Trace from orion.eclipse.org:

postMessage (0) - MESSAGE QUEUED: lint
javascriptPlugin.js:182 worker_ready (0): worker_ready
javascriptPlugin.js:149 postMessage (0) - START {"options":{"libs":["browser","ecma5","angular"],"loadEagerly":["/file/mrennie-OrionContent/angular-demo/public/index.html"]}}
javascriptPlugin.js:195 server_ready (0): start_server
javascriptPlugin.js:304 clearing MESSAGE queue: lint
javascriptPlugin.js:141 postMessage (1) - SENT lint
javascriptPlugin.js:141 postMessage (1) - SENT read
javascriptPlugin.js:141 postMessage (1) - SENT read

Trace from beta3:

postMessage (0) - MESSAGE QUEUED: lint
javascriptPlugin.js:182 worker_ready (0): worker_ready
javascriptPlugin.js:149 postMessage (0) - START {"options":{"libs":["browser","ecma5","angular"],"loadEagerly":["/code/file/mrennie-OrionContent/snorthov | angular-demo/public/index.html"]}}
javascriptPlugin.js:195 server_ready (0): start_server
javascriptPlugin.js:304 clearing MESSAGE queue: lint
javascriptPlugin.js:141 postMessage (1) - SENT lint
javascriptPlugin.js:141 postMessage (1) - SENT read
javascriptPlugin.js:141 postMessage (1) - SENT read
Comment 13 Michael Rennie CLA 2016-03-17 14:19:20 EDT
Closing fixed. The trace is identical now across all servers / platforms