Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja.osipov@gmail.com>
To: Leonid Vasiliev <lvasiliev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] Add a cancellation guard to cpipe flush callback
Date: Thu, 5 Dec 2019 10:27:06 +0300	[thread overview]
Message-ID: <20191205072706.GA16690@atlas> (raw)
In-Reply-To: <65b9d108-fe36-1c9b-82c0-60e98efce658@tarantool.org>

* Leonid Vasiliev <lvasiliev@tarantool.org> [19/12/05 10:24]:
> On 12/3/19 9:02 PM, Konstantin Osipov wrote:
> > * Leonid Vasiliev <lvasiliev@tarantool.org> [19/12/03 19:36]:
> > > https://github.com/tarantool/tarantool/issues/4127
> > > https://github.com/tarantool/tarantool/tree/lvasiliev/gh-4127-WAL-thread-stucks
> > 
> > Looks like a great catch.
> > 
> > > We need to set a thread cancellation guard, because
> > > another thread may cancel the current thread
> > > (write() is a cancellation point in ev_async_send)
> > > and the activation of the ev_async watcher
> > > through ev_async_send will fail.
> > 
> > I still don't get from the explanation why it is relevant that
> > ev_async_send mustn't fail?
> 
> The cause of why the ev_async_send mustn't fail is unwanted behavior of the
> tarantool instance. For example: first thread flush cpipe input to a
> endpoint output and go away while trying to call ev_async_send (write() -
> cancellation point). Now stailq_empty(&endpoint->output) is false. After
> that, another thread flush cpipe input to the same endpoint, but it didn't
> try to call ev_async_send, because output_was_empty is false. As result: a
> thread of endpoint->consumer didn't wake-up (blocked on epoll_wait). The
> same situation described in
> https://github.com/tarantool/tarantool/issues/4127:
> 

Looks like an explanation that deserves to be in a comment prior
to pthread_setcancelstate().

The issue is, however, if a thread is cancelled and disappears
before deregistering from cbus, a lot of other bad things will
happen - because all of its registration entries will sit there.
The memory, luckily, will not go away, but I am not sure anyone
but the creating thread can deregister the memory structures
safaly. Looks like this could be covered with a unit test, what do
you think?

> at main thread:
> 	from void wal_free(void):
> 		cbus_stop_loop(&writer->wal_pipe);
> 		if (cord_join(&writer->cord)) {...}  // wait the "wal" thread
> 
> at "wal" thread:
> 	don't try to call cbus_stop_loop_f (for the reasons described above)
> 	blocked at epoll_wait()
> 
> > 
> > 

-- 
Konstantin Osipov, Moscow, Russia

  reply	other threads:[~2019-12-05  7:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03 16:33 Leonid Vasiliev
2019-12-03 18:02 ` Konstantin Osipov
2019-12-05  7:22   ` Leonid Vasiliev
2019-12-05  7:27     ` Konstantin Osipov [this message]
2019-12-23 12:44       ` Leonid Vasiliev
2019-12-23 12:55         ` Konstantin Osipov
2019-12-24 15:27           ` Leonid Vasiliev
2019-12-24 15:33             ` Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191205072706.GA16690@atlas \
    --to=kostja.osipov@gmail.com \
    --cc=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] Add a cancellation guard to cpipe flush callback' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox