Re: Re: BUG #8647: Backend process hangs and becomes unkillable when SSL client looses connection

From: Alexander Kukushkin <cyberdemn(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Re: BUG #8647: Backend process hangs and becomes unkillable when SSL client looses connection
Date: 2013-12-05 16:07:55
Message-ID: CAFh8B=nnR-zWc5N5n-D7jhx5VquZZT1k87Dych_Az+pPzJKWxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

2013/12/5 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

> Alexander Kukushkin <cyberdemn(at)gmail(dot)com> writes:
> > After analysing source code of postgres and openssl I've found (at least
> I
> > think) the reason why it is happening:
> >
> ----------------------------------------------------------------------------------------------------------------------------
> > static int
> > my_sock_write(BIO *h, const char *buf, int size)
> > {
> > int res = 0;
>
> > res = send(h->num, buf, size, 0);
> > if (res <= 0)
> > {
> > if (errno == EINTR)
> > {
> > BIO_set_retry_write(h);
> > }
> > }
>
> > return res;
> > }
>
> BTW, I was looking at that function the other day and thinking it was
> wrong: if the send() returns exactly zero, it hasn't set errno has it?
> But perhaps that case never arises.
>
> regards, tom lane
>

According to documentation, "On success, these calls return the number of
characters sent. On error, -1 is returned, and errno is set appropriately."
So, return zero is not an error and errno should not be set.
I guess you could get zero only in case when you are sending an empty
buffer or in nonblocking mode, which obviously is not the case.

But, returning to my original message... I noticed that I've made stupid
copy&paste error

static int
my_sock_write(BIO *h, const char *buf, int size)
{
int res = 0;

res = send(h->num, buf, size, 0);
+ BIO_clear_retry_flags(h); // <-- here, should be "h" not "b" as in
original message.

if (res <= 0)
{
if (errno == EINTR)
{
BIO_set_retry_write(h);
}

Best regards,
Alexander Kukushkin

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2013-12-05 17:33:10 Re: Re: BUG #8647: Backend process hangs and becomes unkillable when SSL client looses connection
Previous Message Tom Lane 2013-12-05 14:54:38 Re: Re: BUG #8647: Backend process hangs and becomes unkillable when SSL client looses connection