@@ -1090,6 +1090,14 @@ fd_http_server_ws_send( fd_http_server_t * http,
1090
1090
return -1 ;
1091
1091
}
1092
1092
1093
+ /* It is possible that ws_conn_id has already been closed by
1094
+ fd_http_server_reserve during staging. If the staging buffer is
1095
+ full, the incoming frame is added to the beginning of the buffer,
1096
+ and any connections that were previously using that allotted space
1097
+ are closed. There is a small chance that ws_conn_id is one of
1098
+ those connections, and has therefore already been closed. */
1099
+ if ( FD_LIKELY ( http -> pollfds [ http -> max_conns + ws_conn_id ].fd == -1 ) ) return -1 ;
1100
+
1093
1101
if ( FD_UNLIKELY ( conn -> send_frame_cnt == http -> max_ws_send_frame_cnt ) ) {
1094
1102
close_conn ( http , ws_conn_id + http -> max_conns , FD_HTTP_SERVER_CONNECTION_CLOSE_WS_CLIENT_TOO_SLOW );
1095
1103
return 0 ;
@@ -1184,7 +1192,7 @@ static void
1184
1192
fd_http_server_evict_until ( fd_http_server_t * http ,
1185
1193
ulong off ) {
1186
1194
conn_treap_fwd_iter_t next ;
1187
- for ( conn_treap_fwd_iter_t it = conn_treap_fwd_iter_init ( http -> conn_treap , http -> conns ); !conn_treap_fwd_iter_idx ( it ); it = next ) {
1195
+ for ( conn_treap_fwd_iter_t it = conn_treap_fwd_iter_init ( http -> conn_treap , http -> conns ); !conn_treap_fwd_iter_done ( it ); it = next ) {
1188
1196
next = conn_treap_fwd_iter_next ( it , http -> conns );
1189
1197
struct fd_http_server_connection * conn = conn_treap_fwd_iter_ele ( it , http -> conns );
1190
1198
@@ -1196,7 +1204,7 @@ fd_http_server_evict_until( fd_http_server_t * http,
1196
1204
}
1197
1205
1198
1206
ws_conn_treap_fwd_iter_t ws_next ;
1199
- for ( ws_conn_treap_fwd_iter_t it = ws_conn_treap_fwd_iter_init ( http -> ws_conn_treap , http -> ws_conns ); !ws_conn_treap_fwd_iter_idx ( it ); it = ws_next ) {
1207
+ for ( ws_conn_treap_fwd_iter_t it = ws_conn_treap_fwd_iter_init ( http -> ws_conn_treap , http -> ws_conns ); !ws_conn_treap_fwd_iter_done ( it ); it = ws_next ) {
1200
1208
ws_next = ws_conn_treap_fwd_iter_next ( it , http -> ws_conns );
1201
1209
struct fd_http_server_ws_connection * conn = ws_conn_treap_fwd_iter_ele ( it , http -> ws_conns );
1202
1210
0 commit comments