MikeL has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl script that uses LWP::Daemon to accept requests via web URLs. Program works great under normal circumstances. However...

I have a poor DSL connection that swamps easily, and just plain "farts" more than occasionally. When this happens, the next request will time out. The connection will come back within a minute or so, but in the meantime, my program will have crashed with:
getnameinfo - Temporary failure in name resolution at /usr/share/perl5/HTTP/Daemon.pm line 182
Line 182:
$uri = $HTTP::URI_CLASS->new($uri, $self->daemon->url);

I'm over my head here, I'm not finding the getnameinfo() call, it looks to me like it's basically just building a string.
Can I just put a 'try' around it? I'd much rather lose this one msg than have the program do a 'die' like this.

Thanks!

Replies are listed 'Best First'.
Re: LWP::Daemon barf on bad DNS (updated)
by haukex (Archbishop) on Aug 30, 2023 at 07:04 UTC
    Can I just put a 'try' around it?

    Without knowing what your code looks like (SSCCE!), I'd say yes, try (e.g. from Try::Tiny or a modern Perl) is a standard way to catch errors like this and to have your code continue after handling the error. It also depends a bit on how your script is being run and how often this happens, if it doesn't happen all too often and you're running your script as a daemon, note there are process managers that will automatically restart crashed daemons.

    Update: Since your last question was about RPi, is this on an RPi? Because there, since Raspbian already runs systemd, I just use that to manage my daemons. For example, here's a .service file I used on a project that used a Mojolicious webserver on an RPi:

    # Docs: https://wiki.debian.org/systemd/Services # Set me up via: # $ sudo ln -s /home/pi/project/my_web.service /etc/systemd/system/ # $ sudo systemctl daemon-reload # $ sudo systemctl enable my_web # $ sudo systemctl start my_web [Unit] Description=My Web Service After=network.target [Service] Type=simple Restart=always Environment="PERL5LIB=/home/pi/perl5/lib/perl5" User=pi Group=pi ExecStart=/home/pi/project/web_app.pl daemon -m production -l http://* +:8080 [Install] WantedBy=multi-user.target

    You can customize how the service gets managed, e.g. with things like KillSignal=SIGINT or RestartSec=30.