Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367149 - Occasional Javascript error in HtmlUtil on startup
Summary: Occasional Javascript error in HtmlUtil on startup
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 1.5   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-20 01:57 EST by Jens Borrmann CLA
Modified: 2012-01-27 11:50 EST (History)
2 users (show)

See Also:


Attachments
Error message when using FireFox (10.28 KB, text/plain)
2011-12-20 01:58 EST, Jens Borrmann CLA
no flags Details
Error message when using Internet Explorer (3.60 KB, text/plain)
2011-12-20 01:59 EST, Jens Borrmann CLA
no flags Details
Error message when using Chrome (24.29 KB, text/plain)
2011-12-20 07:54 EST, Harald Groß CLA
no flags Details
Error message when using Safari (24.26 KB, text/plain)
2011-12-20 07:55 EST, Harald Groß CLA
no flags Details
Zipfile containing headers and response of the javascript library (396.35 KB, application/x-zip-compressed)
2011-12-20 09:45 EST, Harald Groß CLA
no flags Details
Zipfile containing response of the javascript library without custom widgets (376.07 KB, application/x-zip-compressed)
2011-12-21 02:24 EST, Harald Groß CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Borrmann CLA 2011-12-20 01:57:58 EST
Build Identifier: 1.4.0.20111209-1413

Occasionally we face Javascript errors during startup of our application. The exact message differs between Firefox and IE. But in both browsers the place where the problem manifests is org.eclipse.rwt.HtmlUtil.removeStyleProperty(). 

In case of an error the execution path leads us through the else block of the method. Using FireBug we observed the parameter "b" (or "target" when using the names of the long version of the JavaScript) and saw that it was either of type org.eclipse.swt.widgets.Shell or org.eclipse.swt.widgets.Composite. We could not get any further information on why the instanceof expression was evaluated to false.

The whole thing seems to be a timing issue. On some of our developers' machines the phenomenon never occurs, while other colleagues face the problem in about 1 of 10 startups. 
When the problem occurs only a server restart helps. Reloading the page or switching browsers does not work. So there seems to be a stable server side error situation.
We were never able to observe the problem when using the debug variant of the client-side library.

Reproducible: Sometimes

Steps to Reproduce:
Start server.
Try to start application.
Comment 1 Jens Borrmann CLA 2011-12-20 01:58:33 EST
Created attachment 208589 [details]
Error message when using FireFox
Comment 2 Jens Borrmann CLA 2011-12-20 01:59:00 EST
Created attachment 208590 [details]
Error message when using Internet Explorer
Comment 3 Tim Buschtoens CLA 2011-12-20 04:42:29 EST
Does it not happen with webkit, or did you not test it with Safari/Chrome?
Comment 4 Harald Groß CLA 2011-12-20 07:54:53 EST
Created attachment 208604 [details]
Error message when using Chrome
Comment 5 Harald Groß CLA 2011-12-20 07:55:25 EST
Created attachment 208606 [details]
Error message when using Safari
Comment 6 Harald Groß CLA 2011-12-20 07:57:24 EST
The problem is independent from the browser. I've attached the logs if tried from Chrome or Safari
Comment 7 Tim Buschtoens CLA 2011-12-20 08:43:44 EST
This is very strange. Do you have this only with your own application, or also with any of the demo applications? Could you perhaps attach the javascript-client-code that was recieved by the browser when such an error occured? In Firbug go to the Network tab, open the request that delivered the JS (the first big one), and copy all Content from Headers and from Answer to a text file.
Comment 8 Harald Groß CLA 2011-12-20 09:45:53 EST
Created attachment 208617 [details]
Zipfile containing headers and response of the javascript library
Comment 9 Tim Buschtoens CLA 2011-12-20 11:05:45 EST
Interresting. The javascript client is delivered TWICE (client-core->custom-widgets->client-code again). Since there is no check against that, the second client partially overwrites the first one, and some classes seem to extend classes from client1, others those of client2, and *booom*, instanceof fails.
Comment 10 Harald Groß CLA 2011-12-21 02:24:59 EST
Created attachment 208657 [details]
Zipfile containing response of the javascript library without custom widgets

We can confirm the duplicate entries in case of error. In the good case the transferred library has half the size.
We found, that we deliver custom widgets too. To eliminate possible problems, we disabled the custom widgets. 
The problem still occurs. The attached response contains only plain rap scripts.
Comment 11 Ralf Sternberg CLA 2011-12-21 05:00:07 EST
This issue reminds me of the problems we had with concurrent requests right after startup (bug 277994). Before RAP 1.5, the first user session had to run "isolated". Can you also reproduce this issue when you ensure that there are no concurrent requests immediately after startup?
Comment 12 Harald Groß CLA 2011-12-21 07:53:04 EST
During the test, there is only one user using the application. It is started as RAP Application in Eclipse, one Browser is accessing it.
During startup a login is performed and the user is directed to a login page if he is not authenticated. After user and password entry the application start is retried.

If I set an breakpoint on the write method of ResourceUtil, I can see that the client.js is registered once per login with its original size. The written file in the .metadata directory is exactly the same as those within the q07 bundle.
Comment 13 Harald Groß CLA 2011-12-22 02:43:49 EST
Although the resourceUtil is writing the client.js in the correct size to the metadata directory on each startup request, this does not affect the cached content in JSLibraryConcatenator. Those stores the mixed content of two times the original client.js which is then delivererd to the browser.
So the problem seems to be similar to those dscribed in bug 277994 you mentioned.
Comment 14 Harald Groß CLA 2011-12-22 09:22:48 EST
After a longer debugging session I have been able to reproduce the problem regularly:
Our application registers a ServiceHandler and embeds an hidden object on the main application page to connect this ServiceHandler periodically. This is used for session and license tracking.
If a browser window is kept open after successful login (so the connect requests to the ServiceHandler are activ) and the server is restarted, then the application will run into the script error if the ServiceHandler is called by the old browser window before the login on the new window has been performed.
Vice versa I have not been able to reproduce the problem, if all browser windows to the application have been closed before restarting the server.
Comment 15 Harald Groß CLA 2011-12-23 07:45:06 EST
The cache is opened for writing during registerJSLibraryServiceHandler() by calling:
JSLibraryConcatenator.startJSConcatenation()
It is kept open until the StartupPage is completely loaded. Another request for a LifeCycle gets mixed up with the orignal request because it is only closed during the generation of the startup page.

I could fix the problem localy by installing a patch bundle where I put a sychnronize block around the getStartupPage in LifeCycleServiceHandler.runLifeCycle()

Thanks for your hints they lead me to this workaround.
Comment 16 Ralf Sternberg CLA 2012-01-27 11:50:53 EST
(In reply to comment #15)
Harald, good to know that you've found a fix that works for you.
We're already in the release candidates of the last service release for 1.4 and we're going to avoid patches that affect internals like this for 1.4.2. Even if unlikely, there's still a risk of introducing a deadlock or degrading performance. Our advice for RAP pre-1.5 has always been to start the server in isolated mode, e.g by opening a firewall not before successful startup.

Since this issue is not present in 1.5 anymore (see comment 11), I'll mark this bug as fixed for 1.5.