NetTalk Central

Author Topic: Re: Best place to process a URL parameter  (Read 3478 times)

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Best place to process a URL parameter
« on: October 07, 2014, 10:15:22 PM »
[ reposted here as the other thread is too long]

Hi Bruce

I have removed the code in 'NewSession' that related to the URL parameter.

The problem persisted and I did more testing.  The situation in the code now is:

The parameter (bparm) is not initialised
bparm is set via: p_web.StoreValue('bparm') in the ProcessLink Procedure
bparm is not altered in any other code

The assumption in the above code is that if the parameter exists then the session variable 'bparm' is stored via StoreValue and if it is not present then it is blank.  Another assumption is that if it was present at the start of a session then the session variable remains at the initial value even when the URL changes. 

Well, it looks to me as if this is not always the case.  When starting the session with ?bparm=bill I included the following in ProcessLink:

  stop('b4 store='&p_web.GSV('bparm'))
  p_web.StoreValue('bparm')    !save any URL parameter
  stop('after store='&p_web.GSV('bparm'))

The result is that frequently the first STOP displays 'bill' and the second displays blank.

I say 'frequently' because the ProcessLink procedure is executed a lot  and sometimes I correctly get bill/bill and sometimes bill/blank.  Sometimes I get bill/blank then blank/bill.

Now, once bill becomes blank my file path names get screwed up.

Of course, as noted before, if I execute without the parameter everything is ok because the pathname is being set thru a login procedure which is not dependent on the parameter.

It looks to me as if the problem is in StoreValue which sounds crazy I know but I cannot get any more granular in my investigation.

Your sage thought appreciated as always.

Keith

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Best place to process a URL parameter
« Reply #1 on: October 07, 2014, 10:18:27 PM »
Hi Keith,

Don't use Stop to debug. Because there are multiple threads running here that is bound to be confusing.

rather do a Trace, and pay particular attention to the thread number - remember that 2 threads can be running "at the same time".
Also be aware that thread numbers are reused.

 self.trace('Thread=' & thread() & ' GSV Before ' & self.GSV('bparm'))
  p_web.StoreValue('bparm')    !save any URL parameter
  self.trace('Value = ' & self.GetValue('bparm') & ' now GSV=' & self.GSV('bparm')


-------------------------------
as your page opens it makes multiple simultaneous requests for .js, .css and image files. since these may be processed before the initial page has completed, they may be sent without a sessionId, and hence may be on "different sessions". This doesn't matter because these are static files.

perhaps include the sessionId in the log, and the .PageRequest that may help you understand.

cheers
Bruce
« Last Edit: October 23, 2014, 10:19:34 PM by Bruce »

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Best place to process a URL parameter
« Reply #2 on: October 08, 2014, 12:08:28 AM »
Thanks Bruce for that info and tip.  I downloaded DebugView and could see the trace outputs.  I have logged the activity to a file and truncated it to just include the NetTalk bits.

I can see that on thread 3 the values are all as they should be but then 'bparm' becomes blank on threads 5 and 4 - I don't know how to interpret that.

What I can say is what I did:

  • Start with http://127.0.0.1:8094?bparm=bill
  • Chose meu item which displays a Form
  • click the lookup button and select a row

In the log (DebugNT.txt attached) rows 400, 401 show the start (bparm=blank, bparm=bill which is correct.

Rows 404,405 came from clicking the menu item.  Rows 419-423 and 436-436 probably also came from the menu item (ProcessLink gets executed lots).

Rows 443,444 probably came from clicking the lookup and 445-449 from selecting the row.

Rows 467-468 probably arose from a subsequent selection after the file name had been trashed.

Does this output make sense - the point is that the 'bparm' value is being blanked.  What is happening?

Thanks

Keith

[attachment deleted by admin]
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Best place to process a URL parameter
« Reply #3 on: October 23, 2014, 12:30:08 AM »
I have found out what is happening in my app but am still not understanding why.

The error occurs when I 'select' from a Lookup browse.

If you look at the attached Debug-View log there are a number of things to see and that I don't understand.  I have added the annotation 'Note n' in green and red and these are the items I particularly want to comment on.

1. The session id changes as I work through the pages - I have always thought that once the session started that the id remained the same so I'd like a comment on that.

2. Note 1 thru Note 4 shows the selection of the ? which pops up the browse 'sservice'.  The value of the Url parameter and username are correct and the thread is 3

3. Notes 5 and 6 shows the program returning from the sservice browse to the form uQuotes.  The thread is now 4.  The URL parameter has changed to blank and teh username is also blank.

Since the username is the variable which specifies a part of the fully qualified file name - the application is now not accessing the correct files.

So, it looks as if the problem is that the thread has changed and that has caused the session variables to be reset. I don't understand why.

The traces are in ProcessLink.

Any comments and clarifications will be appreciated.

Keith

PS

When I 'select' the service (from service browse) and thread 4 starts, NewSession is executed and the session values (URL parameter and username) are blanked.

[attachment deleted by admin]
« Last Edit: October 23, 2014, 10:19:04 PM by Bruce »
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Best place to process a URL parameter
« Reply #4 on: October 23, 2014, 01:50:10 PM »
The session ID changing is the root of your problems so I would be focusing on why that happens. I don't think it is NT as this effect would break everyone's apps so I would focus on searching your app for any code that would delete the sessionid and force NT to issue a new sessionid.

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Best place to process a URL parameter
« Reply #5 on: October 23, 2014, 09:14:23 PM »
Kevin

Can you please clarify this for me: is it the case that the session id that is allocated at the beginning  should be maintained throughout until either the session expires or is closed?

This has always been my assumption but Bruce did say (above):

as your page opens it makes multiple simultaneous requests for .js, .css and image files. since these may be processed before the initial page has completed, they may be sent without a sessionId, and hence may be on "different sessions". This doesn't matter because these are static files.


However, I see with the trace that the session id does change in my app even when I am not executing with the URL parameter. The app seems to work ok but I don't write data into tables with the hope that I can separate them by session id.

I have another app in development in which I make extensive use of memory tables to store data based on session id and again, have had no problems in testing.  I will now trace that app to determine if the session id changes.

This is fundamental and I need to understand it.  I have looked at my app and hand code and I do not 'delete the session id'.

Thanks

Keith
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Best place to process a URL parameter
« Reply #6 on: October 23, 2014, 09:34:25 PM »
I have now checked another app that I am developing and the session id does not change, at least over a dozen or so operations.  Also, NewSession gets called once.

So, I am a bit relieved but now have to find out what has happened in what seemed to be a straightforward application.

Keith
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Best place to process a URL parameter
« Reply #7 on: October 23, 2014, 10:30:08 PM »
>> 1. The session id changes as I work through the pages - I have always thought that once the session started that the id remained the same so I'd like a comment on that.

A session ID can change during a login if the p_web.site.ChangeSessionOnLogInOut property is set. This is set via a template option in the web server procedure, Security tab, "Change Session on Login".

However this change preserves all the session values etc - so it should be a seamless change for you. (the exception would be where you are using the SessionId in your own mem tables etc at which point the user will be disconnected from these rows.)

>> So, it looks as if the problem is that the thread has changed and that has caused the session variables to be reset. I don't understand why.

Every incoming request takes place on it's own thread. If you have multiple requests happening at the same time then you'll see thread 4 and 5 and so on come into play.

If you never see thread 3 again then that's a sign that that thread never ended. Usually a sign of a bug in your code causing the thread to get into an endless loop, or wait infinity for some SQL request, or perhaps choke on a corrupt TPS file or whatever. Debug by inspecting the last request handled by that thread, and follow the logic of that thread to see if it ends.

Each incoming request contains the SessionID as a cookie. The most likely cause of a NewSession being generated is if this cookie is lost, or indeed if the request is coming from another browser (ie another user.) Because your exe can serve multiple users at the same time, it's necessary to bear that in mind when viewing the logs. If your thread numbers are > 3 then that's another sign you have multiple simultaneous users in play.

Of course a session can also time-out on the server side. the time it lives for (since the last request) is set in the WebServer, Advanced tab. In this case the request will come though with a session ID, but the server side will have no recollection of that session, so all the session values will be blank.

Cheers
Bruce




Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Best place to process a URL parameter
« Reply #8 on: October 24, 2014, 02:18:42 AM »
Hi Bruce and Kevin

FINALLY SOLVED.  :)

Thanks for being patient in this long saga.  Now that I understand what I did its hard to believe that I didn't see it straightaway.  But I have learned a lot so 'there is no great loss without some small gain' (as was once famously said.  Although in this case the gain has been great too.

The Session ID was changing because in my Process Link code I was re-running the code that set the login and level values and the  p_web.site.ChangeSessionOnLogInOut property was set as the default.  I just utterly failed to appreciate that  p_web.SetSessionLoggedIn(1) did more than moving 1 to a field.

So, all I had to do was to ensure that I only ran the code once and the Session IDs stopped changing and the code executed properly.

Cheers

Keith
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27