Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org,
	Sergey Kaplun <skaplun@tarantool.org>,
	e.temirgaleev@tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 3/3] sysprof: release resources on a halted profiler
Date: Mon,  2 Nov 2026 16:12:51 +0300	[thread overview]
Message-ID: <dfebb0ac14dd0c7e8eae2d0bda118ad6ed9d9e2e.1793624427.git.estetus@gmail.com> (raw)
In-Reply-To: <cover.1793624427.git.estetus@gmail.com>

From: Sergey Bronnikov <sergeyb@tarantool.org>

If the stream fails (e.g., because of ENOSPC), the profiler moves
to the SPS_HALT state. `lj_sysprof_stop()` returns PROFILE_ERRIO
but does not call the `on_stop` callback, so the profile context
and the output file descriptor are leaked.

Call `on_stop` when the halted profiler is stopped, as it is
already done when starting fails or when the stream is stopped in
a regular way. Preserve the saved errno because `on_stop` may
change it.

Follows up tarantool/tarantool#11620
---
 src/lj_sysprof.c                                            | 4 +++-
 test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/lj_sysprof.c b/src/lj_sysprof.c
index 99bcc088..667c93a8 100644
--- a/src/lj_sysprof.c
+++ b/src/lj_sysprof.c
@@ -509,9 +509,11 @@ int lj_sysprof_stop(lua_State *L)
   lj_profile_timer_stop(&sp->timer);
 
   if (SPS_HALT == sp->state) {
-    errno = sp->saved_errno;
+    const int saved_errno = sp->saved_errno;
     sp->state = SPS_IDLE;
     /* wbuf was terminated when error occurred. */
+    sp->on_stop(sp->opt.ctx, sp->out.buf);
+    errno = saved_errno;
     return PROFILE_ERRIO;
   }
 
diff --git a/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c b/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c
index 0f5ffe53..3c9ac05d 100644
--- a/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c
+++ b/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c
@@ -120,6 +120,8 @@ static int sysprof_enospc_during_sampling(void *test_state)
 	errno = 0;
 	assert_int_equal(luaM_sysprof_stop(L), PROFILE_ERRIO);
 	assert_int_equal(errno, ENOSPC);
+	/* The error path releases the profiler resources. */
+	assert_int_equal(ctx.on_stop_calls, 1);
 
 	/* Counters are still available. */
 	assert_true(luaM_sysprof_report(&counters) == PROFILE_SUCCESS);
-- 
2.56.0


      parent reply	other threads:[~2026-11-02 13:14 UTC|newest]

Thread overview: 4+ 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-02 13:12 ` [Tarantool-patches] [PATCH luajit 2/3] sysprof: fix crash on a failed stream flush Sergey Bronnikov via Tarantool-patches
2026-11-02 13:12 ` Sergey Bronnikov via Tarantool-patches [this message]

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=dfebb0ac14dd0c7e8eae2d0bda118ad6ed9d9e2e.1793624427.git.estetus@gmail.com \
    --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 3/3] sysprof: release resources on a halted profiler' \
    /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