[Openvpn-devel,v3] manage: stop polling the listen socket while a client is connected
Commit Message
From: Gianmarco De Gregori <gianmarco@mandelbit.com>
In server mode the management listen socket stays in the persistent
event set after a client is accepted. A second connection queued on it
keeps it readable, so every event wait returns immediately for the
management, management_io() finds nothing to do on the client socket,
and the server spins at 100% CPU while timers starve.
Remove sd_top from the event set on accept; it is re-added when the
state goes back to MS_LISTEN. Reset the cached state on removal, so the
next update registers the right socket even after an accept or close in
a standalone management loop, and skip the removal when nothing is
registered.
Trac: #681
Change-Id: I06302e82cdc7c98503430500daa4ec95f5ce961f
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2212
---
This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2212
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
@@ -344,6 +344,17 @@
#endif
}
+#ifndef _WIN32
+static void
+man_delete_event(struct management *man, const socket_descriptor_t sd)
+{
+ if (man->persist.callback.delete_event)
+ {
+ (*man->persist.callback.delete_event)(man->persist.callback.arg, sd);
+ }
+}
+#endif
+
static void
man_close_socket(struct management *man, const socket_descriptor_t sd)
{
@@ -352,10 +363,7 @@
* Windows doesn't need this because the ne32 event is permanently
* enabled at struct management scope.
*/
- if (man->persist.callback.delete_event)
- {
- (*man->persist.callback.delete_event)(man->persist.callback.arg, sd);
- }
+ man_delete_event(man, sd);
#endif
openvpn_close_socket(sd);
}
@@ -2070,6 +2078,8 @@
{
#ifdef _WIN32
man_stop_ne32(man);
+#else
+ man_delete_event(man, man->connection.sd_top);
#endif
}
@@ -4057,9 +4057,10 @@
management_delete_event(void *arg, event_t event)
{
struct multi_context *m = (struct multi_context *)arg;
- if (m->multi_io)
+ if (m->multi_io && m->multi_io->management_persist_flags)
{
multi_io_delete_event(m->multi_io, event);
+ m->multi_io->management_persist_flags = 0;
}
}