CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Unix - Thread issue?

 



sdebeaubien
Novice

Dec 16, 2009, 10:08 AM

Post #1 of 11 (1332 views)
Unix - Thread issue? Can't Post

I'm mystified. My dev box is a Win32 box running Vista, Tomcat 6 and ActivePerl. I have a login handler app, I'm trying to make this new login routine part of an existing app. On Windows it runs fine. I move it to Unix (target Prod architecture), and I get strange behavior. If I access the app too quickly again, it appears I have "reentered" the existing thread, and that the thread never exited the app, instead, it "picks up" in one of the subroutines??? I've checked and rechecked my code, I cannot find any issues. I am completely stumped to try and explain this behavior.

I'm hesitant to post the code now because it's large (350+ lines) and it already has tons of debug in it. I can reduce it some (removing comments and so forth). I'm just wondering if this rings a bell with anybody?

TIA

-Scottty
Denver


sdebeaubien
Novice

Dec 16, 2009, 12:34 PM

Post #2 of 11 (1322 views)
Re: [sdebeaubien] Unix - Thread issue? [In reply to] Can't Post

Never mind. I still have no idea what is happening here, but I realized it was calling _all_ subroutines in order from the main procedure, but not executing any other code in the main for some reason. So, I moved all the main code into a "mainApp" subroutine, and called that _only_ from main, and now it works every time. Weird, huh?


sdebeaubien
Novice

Dec 16, 2009, 2:00 PM

Post #3 of 11 (1317 views)
Re: [sdebeaubien] Unix - Thread issue? [In reply to] Can't Post

I finally found the source of the problem! I am posting this so others won't tread down this pathway unawares.

The Win32 box was not caching the CGI object, but Linux was. Here was my line of code:

my $cgi = new CGI;

Apparently, anything in the "my" namespace gets cached in linux. I finally had to create a routine to "reinit" all that data that I had under the "my" namespace - including the query object returned from the "new CGI" call and that fixed my issue totally.

Hope this helps somebody else someday!


FishMonger
Veteran / Moderator

Dec 16, 2009, 3:47 PM

Post #4 of 11 (1310 views)
Re: [sdebeaubien] Unix - Thread issue? [In reply to] Can't Post

You have a wrong assumption of the cause.

"my" is not a namespace. "my" is a keyword that creates a lexically scoped variable. The package keyword is used to create a namespace

You never showed your code and your description of the problem is vague and incomplete, so we can only make guesses. My guess is that you declared your vars in the wrong scope and if you had code that failed to execute, then that would indicate a logic error.


(This post was edited by FishMonger on Dec 16, 2009, 3:50 PM)


sdebeaubien
Novice

Dec 16, 2009, 4:04 PM

Post #5 of 11 (1305 views)
Re: [FishMonger] Unix - Thread issue? [In reply to] Can't Post

It was just interesting that the code always worked in Win32 but failed every time in Linux. That's what made me think the "my" vars were being cached somehow. When I made them all into basically just declarations, then set them explicitly elsewhere, that seemed to do the trick. The real problem one was the:

my $cgi = new CGI;

when I made that one statement into:

my $cgi;

$cgi = new CGI;

then everything worked. It's mystifying to me how anything preceded by a "my" keyword could get cached or ??? But, as I said, that apparently was what was happening.


FishMonger
Veteran / Moderator

Dec 16, 2009, 4:40 PM

Post #6 of 11 (1301 views)
Re: [sdebeaubien] Unix - Thread issue? [In reply to] Can't Post


Quote
When I made them all into basically just declarations, then set them explicitly elsewhere, that seemed to do the trick.


That's because you ended up declaring them in a parent scope. Vars declared with the my keyword are accessible within their enclosing block, not outside of that block.

It's a very good bet that you're not using the strict pragma, which would have given you a compilation error message.

If you want to show us your before and after code, we can give you a more detailed explanation.

For example:

Code
#!/usr/bin/perl 

use strict;
use warnings;

{
# this var is not accessable outside of this block
my $name = 'FishMonger';
}

print $name;

That code will generate this compilation error:

Quote
Global symbol "$name" requires explicit package name at ...


You probably should read this: http://search.cpan.org/~dapm/perl-5.10.1/pod/perlfunc.pod#my


(This post was edited by FishMonger on Dec 16, 2009, 4:44 PM)


sdebeaubien
Novice

Dec 16, 2009, 5:18 PM

Post #7 of 11 (1297 views)
Re: [FishMonger] Unix - Thread issue? [In reply to] Can't Post

Interesting, but it's _not_ a scoping issue. I understand scope, very well. The problem, as I said, was somehow that Linux, or the version of Perl my server's are running under prod are caching the "my" vars (at least the ones that are in the _outer_ scope) between invocations. I found that if I re-invoked the app within a few seconds (anywhere between 0-15s) I would get the "odd" behavior. If, however, I waited somewhere more than 15s, then I would get "correct" behavior.

I found if I was somehow able to gen two requests simultaneously, the first would fail and the 2nd would be OK. This led me to believe it was some kind of weird "caching" behavior in the thread inside the server under Linux. It was baffling to me how it happened. I could probably reduce it to a very simple set of sample code now that I understand the issue.

I'd be happy to do that, only, it probably would only show the error on the servers I was using. Maybe...


FishMonger
Veteran / Moderator

Dec 16, 2009, 7:01 PM

Post #8 of 11 (1292 views)
Re: [sdebeaubien] Unix - Thread issue? [In reply to] Can't Post


Quote
When I made them all into basically just declarations, then set them explicitly elsewhere, that seemed to do the trick.


That statement by itself tells you, without a doubt, that you had a scoping issue.

Now, you most likely have/had one or more contributing factors.

a) The cgi object can and I think by default does cache form submission data. That "feature" can be turned off.

b) Tomcat configuration is very likely slightly different between Windows and Linux.

c) Cache on the local box(es) that are used to call you app.

d) Other differences that I can't think of at the moment.


Quote
If I access the app too quickly again, it appears I have "reentered" the existing thread, and that the thread never exited the app, instead, it "picks up" in one of the subroutines?

That is not possible.


savo
User

Dec 18, 2009, 12:26 PM

Post #9 of 11 (1244 views)
Re: [FishMonger] Unix - Thread issue? [In reply to] Can't Post

doesn't mod_perl do that?


FishMonger
Veteran / Moderator

Dec 18, 2009, 12:37 PM

Post #10 of 11 (1241 views)
Re: [savo] Unix - Thread issue? [In reply to] Can't Post


In Reply To
doesn't mod_perl do that?

If you mean that it "picks up" in one of the subroutines, then no it doesn't.

mod_perl allows you to execute the script without having the expensive start-up overhead. It does not execute/enter a script inside some random subroutine of the script.


savo
User

Dec 18, 2009, 2:39 PM

Post #11 of 11 (1234 views)
Re: [FishMonger] Unix - Thread issue? [In reply to] Can't Post

I was thinking of this

http://modperlbook.org/html/6-2-Exposing-Apache-Registry-Secrets.html

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives