You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by "Rosenbaum, Larry M." <ro...@ornl.gov> on 2006/08/04 20:16:58 UTC

DnsResolver.pm gives up unnecessarily on EACCES result

SpamAssassin version 3.1.4
  running on Perl version 5.8.7
SunOS email 5.9 Generic_118558-10 sun4u sparc SUNW,Sun-Fire-V210

In the connect_sock() method in DnsResolver.pm, there is a loop starting
at line 177 that starts out like this:

  # find next available unprivileged port (1024 - 65535)
  # starting at a random value to spread out use of ports
  my $port_offset = int(rand(64511));  # 65535 - 1024
  for (my $i = 0; $i<64511; $i++) {
    my $lport = 1024 + (($port_offset + $i) % 64511);

So it picks out a random number in the 1024-65535 range, and uses it as
the LocalPort option to IO::Socket::INET().  If it gets a EADDRINUSE
error, it tries the next number in sequence for LocalPort.  If it gets
any other error, it gives up trying to create the socket.

The problem is that on our (Solaris) system, the socket creation
sometimes fails with EACCES rather than EADDRINUSE.  This causes the
code to give up when it could have succeeded by just trying another
local port number.

1) Could the code be changed to treat EACCES the same as EADDRINUSE?

2) Better yet, why is the code trying to specify the LocalPort number
instead of letting the system pick one?

Thanks, Larry

Re: DnsResolver.pm gives up unnecessarily on EACCES result

Posted by Vincent Li <vi...@gmail.com>.
2006/8/4, Rosenbaum, Larry M. <ro...@ornl.gov>:
> SpamAssassin version 3.1.4
>   running on Perl version 5.8.7
> SunOS email 5.9 Generic_118558-10 sun4u sparc SUNW,Sun-Fire-V210
>
> In the connect_sock() method in DnsResolver.pm, there is a loop starting
> at line 177 that starts out like this:
>
>   # find next available unprivileged port (1024 - 65535)
>   # starting at a random value to spread out use of ports
>   my $port_offset = int(rand(64511));  # 65535 - 1024
>   for (my $i = 0; $i<64511; $i++) {
>     my $lport = 1024 + (($port_offset + $i) % 64511);
>
> So it picks out a random number in the 1024-65535 range, and uses it as
> the LocalPort option to IO::Socket::INET().  If it gets a EADDRINUSE
> error, it tries the next number in sequence for LocalPort.  If it gets
> any other error, it gives up trying to create the socket.
>
> The problem is that on our (Solaris) system, the socket creation
> sometimes fails with EACCES rather than EADDRINUSE.  This causes the
> code to give up when it could have succeeded by just trying another
> local port number.
>
> 1) Could the code be changed to treat EACCES the same as EADDRINUSE?
>
> 2) Better yet, why is the code trying to specify the LocalPort number
> instead of letting the system pick one?
>

For question 2), See http://issues.apache.org/SpamAssassin/show_bug.cgi?id=3997

> Thanks, Larry
>