DWR

Reverse ajax polling starts before a script session id is determined

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 3.0.RC2
  • Component/s: Engine
  • Documentation Required:
    No
  • Description:
    Hide
    The reverse ajax poll can start before the scriptSessionId is created. This can result in 2 scriptSessions being created for a single page.

    If the following happens on page load:
    1. include engine.js
    2. start reverse ajax polling
    3. invoke a remote method which affects the script session

    Here's what happens:
    A script session is created for 1. but the scriptSessionId is not returned before 2. fires
    scriptSessionId is null for 2. so another script session is created
    3. uses the script session id from 1. since 2. has not returned yet
    when 2. returns, the script session id changes
    all subsequent dwr calls use the scriptSessionId returned from 2.
    there are no pointers to script session 1 and it is effectively lost... therefore any initialization done in 3. is lost.

    The current workaround is this:
    function initReverseAjax() {
       if (dwr.engine._scriptSessionId == null) {
          setTimeout("initReverseAjax()", 2000);
       } else {
          dwr.engine.setActiveReverseAjax(true);
       }
    }

    See this thread for more info:
    http://www.nabble.com/How-to-execute-a-task-by-aiming-the-output-at-a-specific-scirpt-session--td22819708.html
    Show
    The reverse ajax poll can start before the scriptSessionId is created. This can result in 2 scriptSessions being created for a single page. If the following happens on page load: 1. include engine.js 2. start reverse ajax polling 3. invoke a remote method which affects the script session Here's what happens: A script session is created for 1. but the scriptSessionId is not returned before 2. fires scriptSessionId is null for 2. so another script session is created 3. uses the script session id from 1. since 2. has not returned yet when 2. returns, the script session id changes all subsequent dwr calls use the scriptSessionId returned from 2. there are no pointers to script session 1 and it is effectively lost... therefore any initialization done in 3. is lost. The current workaround is this: function initReverseAjax() {    if (dwr.engine._scriptSessionId == null) {       setTimeout("initReverseAjax()", 2000);    } else {       dwr.engine.setActiveReverseAjax(true);    } } See this thread for more info: http://www.nabble.com/How-to-execute-a-task-by-aiming-the-output-at-a-specific-scirpt-session--td22819708.html

Issue Links

Activity

Hide
David Marginian added a comment - 07/Apr/09 9:26 PM

Per Mike on the mailing list:

Hi Lance and others,

I think we discussed the solution for this quite a long time ago on the mailing list, when talking about how to make engine.js static for 3.0 (previously the script session id was merged into a dynamically generated engine.js).

IIRC it goes something like this:

*
When the page is loaded there will be no script session id, neither before or after the inclusion of engine.js.
*
The first remote call from the DWR layer will be done in |ordered| mode (an existing feature in DWR) to ensure that no other call takes place until it returns. As it will send a null scriptSessionId to the server, it will create a new id and return back to the client, so the id can be set in the DWR client layer for the remainder of the page lifetime.
*
The first remote call (for this page's lifetime) could be the user code's first remote call, the first Reverse Ajax poll, or the System.pageLoaded call.
*
After the script session id has been set the DWR client layer can go back to normal/non-ordered mode.

If things haven't changed since we discussed this, I think this is the correct way to implement/correct this feature.

Best regards
Mike

Show
David Marginian added a comment - 07/Apr/09 9:26 PM Per Mike on the mailing list: Hi Lance and others, I think we discussed the solution for this quite a long time ago on the mailing list, when talking about how to make engine.js static for 3.0 (previously the script session id was merged into a dynamically generated engine.js). IIRC it goes something like this: * When the page is loaded there will be no script session id, neither before or after the inclusion of engine.js. * The first remote call from the DWR layer will be done in |ordered| mode (an existing feature in DWR) to ensure that no other call takes place until it returns. As it will send a null scriptSessionId to the server, it will create a new id and return back to the client, so the id can be set in the DWR client layer for the remainder of the page lifetime. * The first remote call (for this page's lifetime) could be the user code's first remote call, the first Reverse Ajax poll, or the System.pageLoaded call. * After the script session id has been set the DWR client layer can go back to normal/non-ordered mode. If things haven't changed since we discussed this, I think this is the correct way to implement/correct this feature. Best regards Mike
Hide
Mike Wilson added a comment - 09/Jul/09 9:25 PM

A recent discussion with Joe in the "File upload progress" thread on the mailing list gives that we can probably switch to client-generated scriptSessionIds. That would take away this problem altogether. Hopefully I can implement that part after the summer.

Show
Mike Wilson added a comment - 09/Jul/09 9:25 PM A recent discussion with Joe in the "File upload progress" thread on the mailing list gives that we can probably switch to client-generated scriptSessionIds. That would take away this problem altogether. Hopefully I can implement that part after the summer.
Hide
David Marginian added a comment - 10/Jul/09 12:18 AM

Thanks for the update Mike.

Show
David Marginian added a comment - 10/Jul/09 12:18 AM Thanks for the update Mike.
Hide
David Marginian added a comment - 10/Jul/09 3:04 AM

Client-generated scriptSessionIds will likely conflict with DWR-320. We probably need to decide which way we want to go.

Show
David Marginian added a comment - 10/Jul/09 3:04 AM Client-generated scriptSessionIds will likely conflict with DWR-320. We probably need to decide which way we want to go.
Hide
Juha Rajakari added a comment - 10/Jul/09 8:05 AM

I believe similar problem arises when engine.js has been included twice on the same page, and there are two reverse ajax services used on the same page.

Then both __System.pageLoaded.dwr requests get different scriptSessionId in the response, and calls to the exposed service methods uses the last one of them (or they use both different ones, which is the error situation! Happens at least with IE8 on the second request to the same page). Then ReverseAjax.dwr request starts to use only the last got scriptSessionId, and therefore the first service does not start, only the last service starts responding to polls.

I guess that ideal would be that both engine.js includes, i.e. calls __System.pageLoaded.dwr would get the same scriptSessionId as response. Or is it just a documention problem...

Show
Juha Rajakari added a comment - 10/Jul/09 8:05 AM I believe similar problem arises when engine.js has been included twice on the same page, and there are two reverse ajax services used on the same page. Then both __System.pageLoaded.dwr requests get different scriptSessionId in the response, and calls to the exposed service methods uses the last one of them (or they use both different ones, which is the error situation! Happens at least with IE8 on the second request to the same page). Then ReverseAjax.dwr request starts to use only the last got scriptSessionId, and therefore the first service does not start, only the last service starts responding to polls. I guess that ideal would be that both engine.js includes, i.e. calls __System.pageLoaded.dwr would get the same scriptSessionId as response. Or is it just a documention problem...
Hide
Mike Wilson added a comment - 10/Jul/09 9:58 AM

David wrote:
> Client-generated scriptSessionIds will likely conflict with DWR-320

I think we can probably handle this without much problems. If the id has already been set server-side, then we just skip running the client-side algorithm. But you are very right that we should coordinate this effort with DWR-320.

Show
Mike Wilson added a comment - 10/Jul/09 9:58 AM David wrote: > Client-generated scriptSessionIds will likely conflict with DWR-320 I think we can probably handle this without much problems. If the id has already been set server-side, then we just skip running the client-side algorithm. But you are very right that we should coordinate this effort with DWR-320.
Hide
Mike Wilson added a comment - 10/Jul/09 9:59 AM

Switching to client-side generation of scriptSessionId still needs to open up for delivery of a server-side scriptSessionId from DWR-320 JSP tags.

Show
Mike Wilson added a comment - 10/Jul/09 9:59 AM Switching to client-side generation of scriptSessionId still needs to open up for delivery of a server-side scriptSessionId from DWR-320 JSP tags.
Hide
Mike Wilson added a comment - 15/Sep/10 11:43 AM

This issue has now been resolved and the script session id is now obtained in a different way that avoids duplicates. See description of changes in DWR-26.

Show
Mike Wilson added a comment - 15/Sep/10 11:43 AM This issue has now been resolved and the script session id is now obtained in a different way that avoids duplicates. See description of changes in DWR-26.

People

Dates

  • Created:
    07/Apr/09 3:59 PM
    Updated:
    15/Sep/10 11:43 AM
    Resolved:
    15/Sep/10 11:43 AM