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

Bug 374934

Summary: RWT Session Initialization problem
Product: [RT] RAP Reporter: Istvan Ballok <Istvan.Ballok>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: andreas.gomolka
Version: 1.3   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch none

Description Istvan Ballok CLA 2012-03-21 11:40:48 EDT
Created attachment 213011 [details]
patch

Problem
=======

On the developer machines and on the live servers, we occasionally had the
problem that after the RAP application was deployed, the user could not start
a session.

A short investigation showed, that the JavaScript, that is in a script tag,
obtained from::

    ?custom_service_handler=org.eclipse.rwt.internal.service.JSLibraryServiceHandler,

is corrupt.

With corrupt I mean that it looks fully garbled. Like this::

    [q$x0.]C.ldaesfsa.udletfVianleu(e$=[$914;1}],)g;eit

Further investigation showed, that two identical script streams are merged
together on the character level. E.g. ``qx.Class.define`` and
``[$0].defaultValue`` ...

I hope this illustrates the problem.

Further investigation showed, that the ``org.eclipse.rwt.internal.service.
JSLibraryServiceHandler`` class returns this garbled script output, from the
static field "uncompressed" (byte[]).

The method ``org.eclipse.rwt.internal.resources.ResourceUtil#write(final File
toWrite, final int[] content)`` is the one that writes (indirectly) to that
buffer.

Furthermore, this buffer is written only during the very first request of the
first RAP session after server startup.

We could reproduce the problem by placing a break point in ``ResourceUtil
#write`` and starting two concurrent sessions after starting the server.

The two session were processed in two separate threads and they both
concurrently wrote to that buffer. Hence, the buffer and the resulting JS had
twice the size, contained everything twice, but merged on the character level.
This is reason for the garbled text.

We understand, that the first request of the first session preforms
some general initialization tasks. However, it is not guarded, and multiple
requests can "qualify" as "the first request of the first session". This
causes havoc!, because they both initialize concurrently.

Solution
========

Our approach to fix this was the following:

The first request of the first few sessions, that arrive before the
initialization is performed, should be processed sequentially. We achieved
this with a small change in the ``org.eclipse.rwt.internal.service.
LifeCycleServiceHandler#runLifeCycle`` method.  For details, please check the
attached patch.

Unfortunately we did not have the time to verify this issue with the current
RAP release. But it is definitely an issue for RAP 1.3.1.

Please consider investigating this issue and applying the proposed patch or a
different solution in the current RAP release.
Comment 1 Ivan Furnadjiev CLA 2012-03-22 03:05:17 EDT
Istvan, we did a lot of changes since 1.3.1. We have a new OSGi bundle (org.eclipse.rap.rwt.osgi) that do the initialization before the first request. More over, there is no longer a service handler that delivers the javascript files - they are registered as a static resources now. That's why, I think that this is not an issue with current 1.5 stream... probably, not an issue with 1.4.2 too.
Comment 2 Ivan Furnadjiev CLA 2012-03-22 08:57:35 EDT
I will close it as a dup of bug 277994.

*** This bug has been marked as a duplicate of bug 277994 ***