From: Evgeniy Temirgaleev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Bronnikov <estetus@gmail.com>,
Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 2/3] sysprof: fix crash on a failed stream flush
Date: Sun, 15 Nov 2026 18:12:55 +0300 [thread overview]
Message-ID: <908b58ba-90b6-4f1d-9737-86432857f39d@tarantool.org> (raw)
In-Reply-To: <ec34b6138bdc9ff271ed2ccf34cc4e1f629e7950.1793624427.git.estetus@gmail.com>
Hi, Sergey! It's an addition to my first letter:
I saw the default implementation of the writer in the lib_misc.c:
```
/*
** Default buffer writer function.
** Just call write to the corresponding descriptor.
*/
static size_t buffer_writer_default(const void **buf_addr, size_t len,
void *opt)
```
It implements the writer definition
```
/*
** Buffer writer which is called on the buffer flush.
** Should return amount of written bytes on success or zero in case of
error.
** *data should contain a buffer of at least the initial size.
** If *data == NULL stream stops.
*/
typedef size_t (*lj_wbuf_writer)(const void **data, size_t len, void *opt);
```
in a way, where unrecoverable error follows with stream stop. It's a
more strong postcondition* ('res == 0 -> errno != 0 && *data == NULL')
(1) than the definition requires ('res == 0 -> errno != 0 || *data ==
NULL') (2).
But all existing LuaJIT code including your lj_wbuf.c patch actually
implies (1), not (2).
I think, it's an option: leave your patch as is with additional fix of
the lj_wbuf_writer requirements to (1) with removing unused STREAM_ERRIO
flag.
--
(*) Actually buffer_writer_default() implements postcondition (1'):
(1') ('res < len -> errno != 0 && *data == NULL')
This must be fixed also (`return 0` instead of `return write_total`,
lib_misc.c, line 123).
---
First letter quoting:
On 11/2/26 4:12 PM, Sergey Bronnikov wrote:
> From: Sergey Bronnikov <sergeyb@tarantool.org>
<snipped>
> Now `wbuf_reserve()` reports whether the stream was stopped during
> the flush. All the write functions skip writing in this case,
> including the loop pumping a large payload through the buffer.
>
> Fixes tarantool/tarantool#11620
> ---
> src/lj_wbuf.c | 20 +-
<snipped>
> @@ -72,7 +80,8 @@ void LJ_FASTCALL lj_wbuf_addu64(struct lj_wbuf *buf, uint64_t n)
> {
> if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
> return;
> - wbuf_reserve(buf, LEB128_U64_MAXSIZE);
> + if (LJ_UNLIKELY(!wbuf_reserve(buf, LEB128_U64_MAXSIZE)))
> + return;
"Is it OK, if the writer report an error only, the buffer content will
be discarded (not written), and we will success in 'pushing more data to
the stream buffer after a hole'?"
> buf->pos += (ptrdiff_t)lj_utils_write_uleb128(buf->pos, n);
> }
>
> @@ -91,11 +100,14 @@ void lj_wbuf_addn(struct lj_wbuf *buf, const void *src, size_t n)
> memcpy(buf->pos, src, left);
> buf->pos += (ptrdiff_t)left;
> lj_wbuf_flush(buf);
> + if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
> + return;
"What would happen if writer() reports an error, but doesn't stop a stream?"
> src = (uint8_t *)src + (ptrdiff_t)left;
> n -= left;
> }
>
> - wbuf_reserve(buf, n);
> + if (LJ_UNLIKELY(!wbuf_reserve(buf, n)))
> + return;
> memcpy(buf->pos, src, n);
> buf->pos += (ptrdiff_t)n;
> }
<snipped>
--
--
Best regards,
Evgeniy Temirgaleev
next prev parent reply other threads:[~2026-11-15 15:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 13:11 [Tarantool-patches] [PATCH luajit 0/3] Fix sysprof crash due to insufficient free disk space Sergey Bronnikov via Tarantool-patches
2026-11-02 13:12 ` [Tarantool-patches] [PATCH luajit 1/3] test: add unit tests for the write buffer Sergey Bronnikov via Tarantool-patches
2026-11-05 18:39 ` Sergey Kaplun via Tarantool-patches
2026-11-11 15:24 ` Evgeniy Temirgaleev via Tarantool-patches
2026-11-02 13:12 ` [Tarantool-patches] [PATCH luajit 2/3] sysprof: fix crash on a failed stream flush Sergey Bronnikov via Tarantool-patches
2026-11-06 10:59 ` Sergey Kaplun via Tarantool-patches
2026-11-11 16:34 ` Evgeniy Temirgaleev via Tarantool-patches
2026-11-15 15:12 ` Evgeniy Temirgaleev via Tarantool-patches [this message]
2026-11-02 13:12 ` [Tarantool-patches] [PATCH luajit 3/3] sysprof: release resources on a halted profiler Sergey Bronnikov via Tarantool-patches
2026-11-06 11:06 ` Sergey Kaplun via Tarantool-patches
2026-11-11 23:29 ` Evgeniy Temirgaleev via Tarantool-patches
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=908b58ba-90b6-4f1d-9737-86432857f39d@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=e.temirgaleev@tarantool.org \
--cc=estetus@gmail.com \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 2/3] sysprof: fix crash on a failed stream flush' \
/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