Skip to content

Commit 847d7e1

Browse files
jherrera-jumpmmcgee-jump
authored andcommitted
http: correctly evict slow connections
1 parent 2f6c79e commit 847d7e1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ballet/http/fd_http_server.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,14 @@ fd_http_server_ws_send( fd_http_server_t * http,
10901090
return -1;
10911091
}
10921092

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+
10931101
if( FD_UNLIKELY( conn->send_frame_cnt==http->max_ws_send_frame_cnt ) ) {
10941102
close_conn( http, ws_conn_id+http->max_conns, FD_HTTP_SERVER_CONNECTION_CLOSE_WS_CLIENT_TOO_SLOW );
10951103
return 0;
@@ -1184,7 +1192,7 @@ static void
11841192
fd_http_server_evict_until( fd_http_server_t * http,
11851193
ulong off ) {
11861194
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 ) {
11881196
next = conn_treap_fwd_iter_next( it, http->conns );
11891197
struct fd_http_server_connection * conn = conn_treap_fwd_iter_ele( it, http->conns );
11901198

@@ -1196,7 +1204,7 @@ fd_http_server_evict_until( fd_http_server_t * http,
11961204
}
11971205

11981206
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 ) {
12001208
ws_next = ws_conn_treap_fwd_iter_next( it, http->ws_conns );
12011209
struct fd_http_server_ws_connection * conn = ws_conn_treap_fwd_iter_ele( it, http->ws_conns );
12021210

0 commit comments

Comments
 (0)