@@ -141,7 +141,7 @@ int ReactorPoll::del(Socket *socket) {
141
141
swoole_print_backtrace_on_error ();
142
142
return SW_ERR;
143
143
}
144
-
144
+ swoole_trace ( " fd=%d " , socket-> fd );
145
145
reactor_->_del (socket);
146
146
return SW_OK;
147
147
}
@@ -169,6 +169,18 @@ int ReactorPoll::wait() {
169
169
SW_REACTOR_CONTINUE;
170
170
} else {
171
171
for (int i = 0 ; i < event_num; i++) {
172
+ /* *
173
+ * A revents value of 0 indicates that no events have occurred on this socket,
174
+ * so the next file descriptor should be checked;
175
+ * likewise, if the file descriptor has already been removed, it should be skipped.
176
+ * It is essential to check whether this file descriptor exists in the reactor,
177
+ * as the event handler may remove a file descriptor with pending but already triggered readable or
178
+ * writable events that have not yet been processed.
179
+ */
180
+ if (events_[i].revents == 0 || !reactor_->exists (events_[i].fd )) {
181
+ continue ;
182
+ }
183
+
172
184
event.socket = reactor_->get_socket (events_[i].fd );
173
185
event.fd = events_[i].fd ;
174
186
event.reactor_id = reactor_->id ;
@@ -244,7 +256,7 @@ int translate_events_from_poll(int16_t events) {
244
256
sw_events |= SW_EVENT_WRITE;
245
257
}
246
258
// ignore ERR and HUP, because event is already processed at IN and OUT handler.
247
- if (((( events & POLLERR) || ( events & POLLHUP)) && !(( events & POLLIN) || ( events & POLLOUT)) )) {
259
+ if ((events & POLLERR || events & POLLHUP) && !(events & POLLIN || events & POLLOUT)) {
248
260
sw_events |= SW_EVENT_ERROR;
249
261
}
250
262
0 commit comments