]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Try shutdown connections before closing
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 4 Jun 2024 08:05:47 +0000 (11:05 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 1 Jul 2024 13:40:56 +0000 (13:40 +0000)
This is to avoid closing connections uncleanly.

src/imap/imap-client.c
src/lib/connection.c
src/login-common/client-common.c
src/login-common/login-proxy.c
src/pop3/pop3-client.c

index 8e5bfa62f32682e0eb3b6a0f6b7011579fdebeb9..f9dbe1d55caf1c2d26b93d67f4a2bed0dc1076f8 100644 (file)
@@ -513,6 +513,8 @@ static void client_default_destroy(struct client *client, const char *reason)
        timeout_remove(&client->to_idle_output);
        timeout_remove(&client->to_idle);
 
+       if (!client->hibernated && client->fd_in == client->fd_out)
+               (void)shutdown(client->fd_out, SHUT_RDWR);
        /* i/ostreams are already closed at this stage, so fd can be closed */
        fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
 
index 0271fa134b0dbc3681ee5db965a47bea0cf8b86f..fa64ba066ce3fa45bb74c9f5cacceef1a6871ab6 100644 (file)
@@ -892,6 +892,8 @@ void connection_disconnect(struct connection *conn)
        i_stream_destroy(&conn->input);
        o_stream_close(conn->output);
        o_stream_destroy(&conn->output);
+       if (conn->fd_in == conn->fd_out)
+               (void)shutdown(conn->fd_out, SHUT_RDWR);
        fd_close_maybe_stdio(&conn->fd_in, &conn->fd_out);
        conn->disconnected = TRUE;
 }
index 211f7620bea2caf33adcda67ce4f12bc87ff70c0..0393bbd0a344e01a990893f66ed371445a14f9de 100644 (file)
@@ -417,6 +417,8 @@ void client_disconnect(struct client *client, const char *reason,
                }
                i_stream_close(client->input);
                o_stream_close(client->output);
+               (void)shutdown(client->fd, SHUT_RDWR);
+
                i_close_fd(&client->fd);
                if (unref) {
                        i_assert(client->refcount > 1);
index 13a2b767f87d84d7dd1522cecaf489822f6876f9..ceccfc632fa225fa6ebad621ae92e57d167092da 100644 (file)
@@ -576,6 +576,7 @@ static void login_proxy_disconnect(struct login_proxy *proxy)
        i_stream_destroy(&proxy->server_input);
        o_stream_destroy(&proxy->server_output);
        if (proxy->server_fd != -1) {
+               (void)shutdown(proxy->server_fd, SHUT_RDWR);
                net_disconnect(proxy->server_fd);
                proxy->server_fd = -1;
        }
index d3d40a43212a4a9ce2d9b29bfdc52faf67fed275..12f1e9d450289ff16e73b26ab580177fb9025015 100644 (file)
@@ -640,6 +640,8 @@ static void client_default_destroy(struct client *client, const char *reason)
        i_stream_destroy(&client->input);
        o_stream_destroy(&client->output);
 
+       if (client->fd_in == client->fd_out)
+               (void)shutdown(client->fd_out, SHUT_RDWR);
        fd_close_maybe_stdio(&client->fd_in, &client->fd_out);
 
        /* Autoexpunging might run for a long time. Disconnect the client