"Can't use an undefined value as a symbol reference" in .cgi file

Does anyone have any alternative suggestion to deal with this same error message>?
Use of uninitialized value $length in numeric eq (==) at webstore.cgi line 130
The browser responds with Error 500

The app works fine out of the box for days. Then it stops being able to send email (from a form) through local host. No error, just doesnt send it, the CGI app still runs fine for quite a while. Then after a couple more goes at testing the email sending, the CGI dies, and reports the line 130 error.

I cant kill the instance because there isn’t any running.
A reboot of the Centos 7 server gets it working again. I havent tried just restarting Apache.

I am also running the same script on Centos 6 (32 bit), and it doesn’t seem to have ever had this problem (it had different problems, but those seem to be well known to Xojo developers)

Logically it cant be wrong permissions or corrupt files. If that were the case, it wouldnt work in the first place, and a reboot wouldnt fix…logically.

p,s. My xojo developer is on holiday. I am just the lowly server/network admin.

Restarting Apache would probably suffice.

Error 500 simply means the code generated an error.

A quick fix would be to have the app quit once a day at a low traffic time. I do that in one of my apps every day at 3:00 AM, using a timer. I check before that no session is active to avoid kicking out the users.

For a more permanent repair, the developer should log all errors in SMTPSocket in order to know what is going on. Appending to a simple text file is easy to set up.

Such problems can have different origins, so I will not speculate at this time.

Thanks Michel
I will get the SMTP logging enabled when I can.

I cant use a cron to quit the app daily though, we are running it from CGI not as a standalone application. There isn’t any application to quit when this issue occurs, or when it has already quit itself through inactivity (which doesnt appear to be very long)

So I’m tossing in this possibility which I had worked through before.
In the newer versions of Linux (mine is Centos 7), there is a security gizmo called systemd.
One of its purposes is to prevent an app, like Apache from writing directly to the /tmp directory.
Instead, you’ll see an entry in your /tmp directory like…
systemd-private-OIvOIK
and in this directory’s sub directories will be whatever files that your CGI attempted to write to /tmp.
I found this out the hard way by “cleaning up” the /tmp directory deleting all of these files.
The next time that I tried to start my app I got the error listed in this thread.
I resolved this problem by restarting Apache, and the /tmp file structure was recreated and all was well again!

Thanks Jeff. I have come across some interesting observations( to me)
my site is also hosted on Centos 7, and we run the Xojo app as a CGI.
I run a bash script every 5 mins to check if the app responds with a http error 500, and if so, run killall on the app name, and send an email notice.

My Apache error logs list these at random times but not all the time:
AH01215: Can’t use an undefined value as a symbol reference at webstoreau.cgi line 118
AH01215: Use of uninitialized value $length in numeric eq (==) at webstoreau.cgi line 130
AH01215: Use of uninitialized value $length in subtraction (-) at webstoreau.cgi line 131

However these seemingly occur when the Xojo Cgi app is both working fine as well as when the client browser gets a HTTP 500 error. So I am not really clear what these errors are really a symptom of. My Cgi app falls over approximately once a day at varied times. even in middle of the night when we have virtually zero traffic, except for my bash script.

Another observation is that we have created a revised version of webstoreau.cgi, and for testing I loaded to a different folder on the same apache server. The result was that if the original of the webstoreau.cgi is running, then opening the second instance of webstoreau.cgi it will result in HTTP 500 error. (and vica versa).

note that I am not saying that was not expected, and I deliberately chose to test in this way based on a hunch. I may be that sometimes the CGI app does not time out properly, and then a new visitor to the site causes a duplication resulting in http error 500.

We do have a timeout function within the cgi app, at about 20 mins.

I have also noticed that if I run killall webstoreau.cgi, and then try to open it again within 10 seconds I get a http 500 error.
I then need to killall again, and wait much longer. maybe 30 seconds and its ok.

I am not really sure what to make from all of this, just throwing my findings out there.

I’m seeing similar to Mark. A CGI Xojo app is run by us for serial number generation and management from a couple of sites. Every so often, the app responds with Error 500. Apache error_log shows Can’t use an undefined value as a symbol reference at myapp.cgi line 118

ps x shows the app apparently running and never timing out. Killing its PID and waiting a some time (perhaps a minute) restores service.

FYI, i use this crude bash script to keep my cgi working. run every 5 mins with cron. It does the job.

[code]if curl -s --head https://site.com.au/~user/cgi-bin/au/xojoapp.cgi | grep “200 OK” > /dev/null

then
echo “No Problems, Carry On.” >/dev/null 2>&1
else
echo “FYI, CGI xojoapp failed, application automatically killed, should be fine now, please check” | mail -s “ALERT xojoapp 64b CGI failed” me@email.com

killall xojoapp

fi[/code]

[quote=295043:@Mark Blake]FYI, i use this crude bash script to keep my cgi working. run every 5 mins with cron. It does the job.

[code]if curl -s --head https://site.com.au/~user/cgi-bin/au/xojoapp.cgi | grep “200 OK” > /dev/null

then
echo “No Problems, Carry On.” >/dev/null 2>&1
else
echo “FYI, CGI xojoapp failed, application automatically killed, should be fine now, please check” | mail -s “ALERT xojoapp 64b CGI failed” me@email.com

killall xojoapp

fi[/code][/quote]
It’s worth noting that this script will also launch the web app every five minutes even if there are no sessions. You may want to check to check if the process is running before calling curl.

Good point Greg. I’ll add this “if” above the curl test and I think this would work

[code]ps auxw | grep xojoapp/xojoapp | grep -v grep > /dev/null

if [ $? != 1]

then
run curl test, blah blah.

[/code]

wait…
it wont make any difference I think.
If the App is running, the curl test will run, and thus keep the App alive because its timeout countdown is renewed. (?)
Thus the App will never timeout as i run the test from cron every 5 mins.

If there’s no process running at all, don’t call your curl method. If there is, call curl and interpret the results.

Btw, I think you’re looking for -ne not !=