]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: istream-seekable - Improve logging after write() errors
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 3 Jun 2024 20:28:23 +0000 (23:28 +0300)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Tue, 3 Dec 2024 13:36:36 +0000 (14:36 +0100)
Also don't silently handle out of disk space errors - log a warning instead.

src/lib/istream-seekable.c
src/lib/test-istream-seekable.c

index b753c9199125c4acbdf3c4fb254bf3bdd7ded91a..786eae3098d95a7d2aa9f7573e25d9354b6a9215 100644 (file)
@@ -243,6 +243,7 @@ static int i_stream_seekable_write_failed(struct seekable_istream *sstream)
        struct istream_private *stream = &sstream->istream;
        void *data;
        size_t old_pos = stream->pos;
+       int write_errno = errno;
 
        i_assert(sstream->fd != -1);
        i_assert(stream->skip == 0);
@@ -256,8 +257,8 @@ static int i_stream_seekable_write_failed(struct seekable_istream *sstream)
                sstream->istream.istream.stream_errno = errno;
                sstream->istream.istream.eof = TRUE;
                io_stream_set_error(&sstream->istream.iostream,
-                                   "istream-seekable: read(%s) failed: %m",
-                                   sstream->temp_path);
+                                   "istream-seekable: write(%s) failed: %s, and attempt to read() it back failed: %m",
+                                   sstream->temp_path, strerror(write_errno));
                return -1;
        }
        sstream->buffer_peak = sstream->write_peak;
@@ -310,14 +311,17 @@ static ssize_t i_stream_seekable_read(struct istream_private *stream)
                ret = write(sstream->fd, data, size);
                i_assert(ret != 0);
                if (ret < 0) {
-                       if (!ENOSPACE(errno)) {
-                               i_error("istream-seekable: write_full(%s) failed: %m",
-                                       sstream->temp_path);
-                       }
+                       const char *orig_temp_path = t_strdup(sstream->temp_path);
+                       int write_errno = errno;
                        if (i_stream_seekable_write_failed(sstream) < 0)
                                return -1;
                        if (!read_from_buffer(sstream, &ret))
                                i_unreached();
+
+                       errno = write_errno;
+                       i_warning("istream-seekable: write_full(%s) failed: %m - "
+                                 "fallback to using only memory",
+                                 orig_temp_path);
                        return ret;
                }
                i_stream_sync(sstream->fd_input);
index 3373f52d6485073dc3f8038608aac2922a0c96de..b151771118047e3958d16c8d995df498debb336e 100644 (file)
@@ -255,9 +255,9 @@ static void test_istream_seekable_failed_writes(void)
        i_close_fd(&fd_callback_fd);
        test_istream_set_size(streams[0], 5);
 
-       test_expect_error_string("istream-seekable: write_full(test-lib.tmp) failed: Bad file descriptor");
        test_assert(i_stream_read(input) == -1);
-       test_expect_no_more_errors();
+       test_assert(input->stream_errno == EBADF);
+       test_assert_strcmp(i_stream_get_error(input), "istream-seekable: write(test-lib.tmp) failed: Bad file descriptor, and attempt to read() it back failed: Bad file descriptor");
 
        test_expect_error_string("file_istream.close((seekable temp-istream for: test seekable)) failed: Bad file descriptor");
        i_stream_unref(&input);