From 1e543361de3a76572a0629ad207be81dfeb7e068 Mon Sep 17 00:00:00 2001
From: EvgenyMekhanik <mechanik20051988@tarantool.org>
Date: Thu, 9 Sep 2021 13:28:36 +0300
Subject: [PATCH] libev: fix error `ev_io_closing` implementation.

Fixed error in implementation of `ev_io_closing`: this function
is called to do same work as `fd_kill` and should call it after
checking fd (in `coio_close` we pass invalid event value, that
leads to assertion in new libev version).
---
 src/lib/core/coio.cc   |  2 +-
 third_party/libev/ev.c | 11 ++++-------
 third_party/libev/ev.h |  2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/lib/core/coio.cc b/src/lib/core/coio.cc
index 5dfe851d4a..5f7c7d2130 100644
--- a/src/lib/core/coio.cc
+++ b/src/lib/core/coio.cc
@@ -776,7 +776,7 @@ coio_wait(int fd, int events, double timeout)
 API_EXPORT int
 coio_close(int fd)
 {
-	ev_io_closing(loop(), fd, EV_CUSTOM);
+	ev_io_closing(loop(), fd);
 	return close(fd);
 }
 
diff --git a/third_party/libev/ev.c b/third_party/libev/ev.c
index 8f0045901b..d6b188477c 100644
--- a/third_party/libev/ev.c
+++ b/third_party/libev/ev.c
@@ -3948,18 +3948,15 @@ ev_io_stop (EV_P_ ev_io *w) EV_THROW
  * Since every watcher is stopped, the select/poll/epoll/whatever
  * backend is properly updated.
  */
-void noinline
-ev_io_closing (EV_P_ int fd, int revents) EV_THROW
+noinline
+void
+ev_io_closing (EV_P_ int fd) EV_THROW
 {
   ev_io *w;
   if (fd < 0 || fd >= anfdmax)
     return;
 
-  while ((w = (ev_io *)anfds [fd].head))
-    {
-      ev_io_stop (EV_A_ w);
-      ev_feed_event (EV_A_ (W)w, revents);
-    }
+  fd_kill(EV_A_ fd);
 }
 
 noinline
diff --git a/third_party/libev/ev.h b/third_party/libev/ev.h
index d42e2df476..7db0523e97 100644
--- a/third_party/libev/ev.h
+++ b/third_party/libev/ev.h
@@ -772,7 +772,7 @@ EV_API_DECL void ev_io_stop        (EV_P_ ev_io *w) EV_THROW;
  * prior to close().
  * Note: if fd was reused and added again it just works.
  */
-EV_API_DECL void ev_io_closing     (EV_P_ int fd, int revents) EV_THROW;
+EV_API_DECL void ev_io_closing     (EV_P_ int fd) EV_THROW;
 
 EV_API_DECL void ev_timer_start    (EV_P_ ev_timer *w) EV_THROW;
 EV_API_DECL void ev_timer_stop     (EV_P_ ev_timer *w) EV_THROW;
-- 
GitLab