Archive for November, 2003

FIX: Suppress Perl “uninitialized value” warnings (strongish medicine for clueful users only)

Monday, November 24th, 2003

If you have written any Perl of moderate complexity, and especially if your Perl of moderate complexity has included CGI and Database interactions, (or any time you have to deal with undef or NULL vs. a blank string, and you might have either of the two), you have run across warnings like this (maybe to STDERR, or maybe in your /etc/httpd/logs/error_log):


Use of uninitialized value in concatenation (.) or string at …


Use of uninitialized value in numeric gt (>) at …


etc.  How can you stop these error messages (warnings, really) from blocking up your logs and your STDERR?


In fact, you should be somewhat concerned at your uninitialized value warnings.  After all, they are there for a reason.  A really good piece of code ought not to generate them, at least in theory.  However, sometimes you want the benefit of use strict and -w warnings, and you have at once good reason not to want to know about uninitialized values.  What might these be?



  • You are doing string interpolation into something where undef and “” are equivalent for your purposes (most web page work)
  • You are doing some conditionals or string comparisons based upon data that come in from one crufty source or another, like CGI, and you don’t want to make a separate case for undef and “”.
  • Relative quick-and-dirtiness where you want at least use strict in order to prevent egregious code but you don’t need to hear about the semantic difference between undefined and the emtpy string.

In these cases, if you are using Perl 5.6+, you are in luck.  You can carefully wrap the specific section of code that has a good reason for not caring about undef values in a block (curly braces) and write:


{
no warnings ‘uninitialized’;
if ( CGI::param(‘name’) ) {
print “Hello, ” . CGI::param(‘name’);
}
else {
print “Hi there.”;
}
}

INFO: What happens to ssh every 2:11:15?

Monday, November 17th, 2003

I was getting a weird artifact in my logs.  A daemon process that was in charge of keeping an ssh connection open to a remote host was restarting ssh every two hours eleven minutes:


myuser 15208 0.0 0.0 0 0 Z 02:01 0:00 [ssh
myuser 15511 0.0 0.0 0 0 Z 04:12 0:00 [ssh
myuser 15548 0.0 0.0 0 0 Z 06:24 0:00 [ssh
myuser 15584 0.0 0.0 0 0 Z 08:35 0:00 [ssh
myuser 15619 0.0 0.3 3408 1704 S 10:46 0:00 ssh -T myhost …


What the heck is going on? I was running this from behind a DSL modem, and I had experienced some intermittent problems with it before. Was it the modem? Googling on the model # indicated nothing similar reported by others. Was it my ISP or Telco? Phone calls to them indicated that 2 hours was the median time between dropped connections for some old modems, but not mine and not my circuit type. Hmm. Many people pointed to the TCP KeepAlive default of 7200 seconds — two hours — but my problem had a period of over two hours. Almost exactly, consistently, two hours eleven minutes.


As it turns out, the TCP KeepAlive time of 7200 seconds plus the default KeepAlive probe interval (75) times the default probe count (9) add up to 2:11:15.


If you want to change this for one reason or another, try:


echo “30” > /proc/sys/net/ipv4/tcp_keepalive_time


… or likewise (remember that you’ll still have 11:15 worth of probe * count; lower those too if you need to know sooner). Better yet, read http://av.stanford.edu/books/tcpip/tcp_keep.htm for some actual theory on the subject.


One good use for this information is if you want to keep a persistent connection open between two machines using, e.g., Net::SSH::sshopen2 for a bidirectional remote connection to a process executed on a remote machine, but you’re on a kind of flaky connection that can cause the connection to get dropped often but briefly, and the nature of the stuff you’re doing is such that you want it to re-connect and try again rather than obliviously sit through the blip.


(The reason I ramble so lengthily on what particularly one might use this for is because you do NOT want to follow these directions if you’re having a more common “momentarily flaky” connection sequela, such as you have terminal sessions that you wish to keep open despite a moment of flakiness — in that case, you do NOT want to enable short TCP keepalives, since they are really “detect deads,” and they will increase the likelihood that your blip in the connection will kill your terminal session.  In that case, you pretty much want to do the OPPPOSITE of this, excepting that 1. if you are behind a NAT router and your connection isn’t actually flaky, you might really be seeing a timeout of the NAT table, not connection flakeage, and so you DO want to put a keepalive in shorter than the NAT table timeout [it’s all a bit much, isn’t it?] 2. you are probably best off just using “screen” and doing a screen -r to reconnect to an old screen when you get reconnected [screen is awesome for all sorts of reasons, and wth screen, if you can divorce yourself from the graphical burden, you’ve essentially got a total multitasking virtual desktop with persistent state as long as you’ve got a vt100 terminal].)


The way I would recommend would be the following:


1. Set up your local ssh_config to make sure you’re using KeepAlive yes.


2. Set up your local tcp settings to have a short keepalive time and probe interval/count.  (Some kernels apparently don’t behave with less than 90 seconds as the keepalive time but I have had success with much lower numbers.)


3. Set up your remote sshd_config to use the ClientAliveInterval and ClientAliveCountMax with reasonable values.  What this does is sort of a reverse and in-band version of what the TCP keepalive is doing on the local machine; the ssh daemon will send an encrypted signal across every ClientAliveInterval seconds and will hang up the connection if it misses CountMax of them in a row; this makes sure that the process you run on the remote machine gets hung up OK.


4. Make sure that your sshopen2 call and the sending and receiving of things along it recognizes when the SSH connection gets closed out and deals with it, such as by an eval loop and a reconnection in the event of $@ .


 

INFO: What happens to ssh every 2:11:15? …

FIX: Evil MSN Search spyware behavior for DNS errors in MSIE

Wednesday, November 12th, 2003

In Microsoft Internet Explorer >= 5, a DNS error (asking for a hostname that doesn’t exist) causes IE to pull an evil stunt and feed the requested URL to http://search.msn.com/dnserror.aspx , where it is used to search MSN and logged for who knows what nefarious purpose.  Rather than being opt-in behavior, this is opt-out, and rather than making it clear with a choice in options like “Automatically search when a site is not found”, opting out is a matter of making this choice:

Tools:Internet Options:Advanced:Search from the Address bar:Do not search from the Address bar.

Irksome.

INFO: Apache SSL error: You have to perform a *full* server restart when you added or removed a certificate …

Friday, November 7th, 2003

Have you seen this spuriously:


Ops, no RSA or DSA server certificate found?!
You have to perform a *full* server restart when you added or removed a certificate and/or key file


in your ssl error log (and of course your Apache didn’t successfully start: ps -aux | grep httpd | wc -l is zero…) when you were using


apachectl restart


…or some utility that in turn used that method for restarting apache?  Try substituting


apachectl stop && apachectl start

 

INFO: Apache SSL error: You have to perform a *full* server restart when you added or removed a certificate … …