Re: BUG #14720: getsockopt(TCP_KEEPALIVE) failed: Option not supported by protocol

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: lizenko79@gmail.com, Michael Paquier <michael.paquier@gmail.com>, pgsql-bugs@postgresql.org
Date: 2017-06-28T13:52:36Z
Lists: pgsql-bugs
I wrote:
> Concretely, something like the attached.  I have no way to test this
> locally, so I'm thinking of just pushing it and seeing what the buildfarm
> says.

So that didn't work: castoroides is still showing

[5953a7e1.1fff:13] LOG:  getsockopt(TCP_KEEPALIVE) failed: Option not supported by protocol
[5953a7e1.1fff:14] STATEMENT:  select name, setting from pg_settings where name like 'enable%';

which implies that TCP_KEEPALIVE_THRESHOLD doesn't exist on Solaris 10.
Evidently, the logic here needs to be along the lines of

#if defined(TCP_KEEPIDLE)
...
#elif defined(TCP_KEEPALIVE_THRESHOLD)
...
#elif defined(TCP_KEEPALIVE) && defined(__darwin__)
...

Or we could make the last test be !defined(__solaris__), but I'm not
sure that's better.  Anybody have an opinion?

As long as I have to touch this code again anyway, I'm also going to
look into Michael's thought of trying to reduce code duplication.
I was unhappy yesterday about how to handle the error messages,
but we could do it like this:

#if defined(TCP_KEEPIDLE)
#define PG_TCP_KEEPALIVE TCP_KEEPIDLE
#define PG_TCP_KEEPALIVE_STR "TCP_KEEPIDLE"
#elif ...

#ifdef PG_TCP_KEEPALIVE
      if (setsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE,
                     (char *) &idle, sizeof(idle)) < 0)
      {
          elog(LOG, "setsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_STR);

which doesn't seem too painful.

			regards, tom lane


Commits

  1. Second try at fixing tcp_keepalives_idle option on Solaris.

  2. Support tcp_keepalives_idle option on Solaris.