# Library(redis): report DNS failure

**URL:** <https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049>\
**Category:** General\
**Created:** [October 16, 2020, 4:16am UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049 "2020-10-16T04:16:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 16, 2020, 4:16am UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/1 "2020-10-16T04:16:08Z")

</div>

In testing library(redis) I mistyped the redis host name in redis\_server/3, and when I ran the redis/2 command it simply blocked forever. Problably should throw an exception like ping does:

```prolog
$ ping: nonexistent
ping: nonexistent: No address associated with hostname

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 21, 2020, 7:32am UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/2 "2020-10-21T07:32:56Z")

</div>

As is, redis\_server/3 does not check the server address. Calls to redis/3 and anything that depend on it are retried after 10ms, doubling on each failure up to one minute. It then keeps trying for a day. You can change these defaults using library(setting).

The question is when to retry and when not. Is a DNS failure sufficiently different from a failed server which may also be permanently failed or inaccessible due to routing or firewall issues.

We could of course let redis\_server/3 do a DNS check. On the other hand, a rebooting cluster may not always have its DNS right from the start. A possible intermediate could be to print some or all connect failures as warnings.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 22, 2020, 6:43pm UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/3 "2020-10-22T18:43:30Z")

</div>

> [@jan](#):
>
> A possible intermediate could be to print some or all connect failures as warnings.

I think this is the proper solution, it keeps the behavior the same, but the user has a warning. (and if necessary the warnings can be silenced). Thanks for your great work.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [October 22, 2020, 6:56pm UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/4 "2020-10-22T18:56:29Z")

</div>

By “print”, do you mean writing to stderr, or calling a logger, or something else? On Windows, would you open a warning window?

(I’m not a fan of printing warnings, but it’s fine to provide some kind of callback for handling error situations; or you might want to throw an exception)

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 22, 2020, 7:10pm UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/5 "2020-10-22T19:10:03Z")

</div>

> [@peter.ludemann](#):
>
> but it’s fine to provide some kind of callback for handling error situations

Something like `onerror(Callback)` as an option for redis\_server/3? Sounds good.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 23, 2020, 8:23am UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/6 "2020-10-23T08:23:17Z")

</div>

> [@peter.ludemann](#):
>
> By “print”, do you mean writing to stderr, or calling a logger, or something else?

_print_ means print\_message/2. That is designed for printing messages and can easily be linked to OS logging facilities (e.g., library(syslog) realizes sending such messages to Unix syslog).

> [@swi](#):
>
> Something like `onerror(Callback)` as an option for [redis\_server/3](https://www.swi-prolog.org/pldoc/doc_for?object=redis_server/3)? Sounds good.

I think we have something for errors, called exceptions 🙂 There is not much you can repair here. There are just two options: try again or give up and raise an exception. The repair needed is typically outside the reach of the client: fix the server or the network.

I will add a sensible message.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 24, 2020, 3:06am UTC](https://swi-prolog.discourse.group/t/library-redis-report-dns-failure/3049/7 "2020-10-24T03:06:33Z")

</div>

> [@jan](#):
>
> I think we have something for errors, called exception

😁

> [@jan](#):
>
> I will add a sensible message.

I think this is good; so that the user is informed about what is happening.
