Skip to content

Commit

Permalink
service: lock pt while using wsi fdtable pos
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac He authored and lws-team committed Apr 14, 2024
1 parent ec76f81 commit e820283
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/core-net/pollfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
context = wsi->a.context;
pt = &context->pt[(int)wsi->tsi];

assert(wsi->position_in_fds_table < (int)pt->fds_count);

#if !defined(LWS_WITH_EVENT_LIBS)
/*
* This only applies when we use the default poll() event loop.
Expand Down Expand Up @@ -112,10 +110,11 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)

ftp->_and = _and;
ftp->_or = _or;
ftp->fd_index = wsi->position_in_fds_table;
ftp->next = NULL;

lws_pt_lock(pt, __func__);
assert(wsi->position_in_fds_table < (int)pt->fds_count);
ftp->fd_index = wsi->position_in_fds_table;

/* place at END of list to maintain order */
ftp1 = (struct lws_foreign_thread_pollfd **)
Expand Down Expand Up @@ -144,13 +143,16 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
*/
_or |= LWS_POLLHUP;
#endif

lws_pt_lock(pt, __func__);
assert(wsi->position_in_fds_table < (int)pt->fds_count);
pfd = &pt->fds[wsi->position_in_fds_table];
pa->fd = wsi->desc.sockfd;
lwsl_wsi_debug(wsi, "fd %d events %d -> %d", pa->fd, pfd->events,
(pfd->events & ~_and) | _or);
pa->prev_events = pfd->events;
pa->events = pfd->events = (short)((pfd->events & ~_and) | _or);
lws_pt_unlock(pt);

pa->fd = wsi->desc.sockfd;
lwsl_wsi_debug(wsi, "fd %d events %d -> %d", pa->fd, pa->prev_events,
pa->events);

if (wsi->mux_substream)
return 0;
Expand Down Expand Up @@ -621,10 +623,7 @@ lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
lws_dll2_get_head(&vhost->same_vh_protocol_owner[n])) {
wsi = lws_container_of(d, struct lws, same_vh_protocol);

assert(wsi->a.protocol &&
wsi->a.protocol->callback == protocol->callback &&
!strcmp(protocol->name, wsi->a.protocol->name));

assert(wsi->a.protocol == protocol);
lws_callback_on_writable(wsi);

} lws_end_foreach_dll_safe(d, d1);
Expand Down

3 comments on commit e820283

@exploman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @lws-team. This assert should not be change.
image
#3110
image

@exploman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cherry pick this to V4.3-stable.

@exploman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fix the incorrect modification on assert by "push -f" at Sat Apr 13, but may not work. So I create a new pull request. #3139

Please sign in to comment.