Skip to content

Commit

Permalink
BUG/MEDIUM: hlua: Don't loop if a lua socket does not consume receive…
Browse files Browse the repository at this point in the history
…d data

If some data are received for a lua socket while the lua script responsible
to consume these data is not ready to do so, for instance because it is
sleeping, the applet is woken up in loop because it never states it will not
consume these data yet.

To fix the issue, in the applet I/O handle, when there are outgoing data, we
always pretend the applet will not consume it. It is the responsibility to
the lua script to reactivate receives by calling Socket.receive() function.

This patch must be backported to every stable version. For 2.4 and older,
si_want_get()/si_cant_get() must be used instead of
applet_will_consume()/applet_wont_consume().
  • Loading branch information
capflam committed Feb 16, 2024
1 parent 38534d3 commit 56e73df
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -2352,8 +2352,10 @@ static void hlua_socket_handler(struct appctx *appctx)
notification_wake(&ctx->wake_on_write);

/* Wake the tasks which wants to read if the buffer contains data. */
if (co_data(sc_oc(sc)))
if (co_data(sc_oc(sc))) {
notification_wake(&ctx->wake_on_read);
applet_wont_consume(appctx);
}

/* If write notifications are registered, we considers we want
* to write, so we clear the blocking flag.
Expand Down Expand Up @@ -2622,6 +2624,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
co_skip(oc, len + skip_at_end);

/* Don't wait anything. */
applet_will_consume(appctx);
appctx_wakeup(appctx);

/* If the pattern reclaim to read all the data
Expand Down

0 comments on commit 56e73df

Please sign in to comment.