Skip to content

Commit 43629f1

Browse files
stackiaclaude
andcommitted
fix: properly close connections when stream ends
Fixes issues where connections were not being closed after RTSP TEARDOWN or when switching channels, causing stale connections in the status display. Fixes #305 Fixes #306 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 27d7a4b commit 43629f1

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/stream.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,12 @@ int stream_handle_fd_event(stream_context_t *ctx, int fd, uint32_t events,
344344
if (ctx->http_proxy.state == HTTP_PROXY_STATE_COMPLETE) {
345345
logger(LOG_DEBUG, "HTTP Proxy: Transfer complete");
346346
/* Set connection to closing state - worker will close it after
347-
* output queue is drained. Return -2 to indicate graceful close. */
347+
* output queue is drained. */
348348
ctx->conn->state = CONN_CLOSING;
349349
/* Trigger EPOLLOUT to flush any remaining data in the queue */
350350
connection_epoll_update_events(
351351
ctx->conn->epfd, ctx->conn->fd,
352352
EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLHUP | EPOLLERR);
353-
return -2;
354353
}
355354
return 0;
356355
}

src/worker.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,11 @@ int worker_run_event_loop(int *listen_sockets, int num_sockets, int notif_fd) {
523523

524524
connection_queue_output_and_flush(c, (const uint8_t *)response,
525525
strlen(response));
526-
} else if (c->state != CONN_CLOSING) {
527-
/* Only handle if not in CONN_CLOSING state.
528-
* CONN_CLOSING connections will be closed by EPOLLOUT handler
529-
* after output queue is drained (graceful close). */
530-
if (!c->headers_sent) {
531-
/* Send 503 if headers not sent yet (no data ever arrived) */
532-
http_send_503(c);
533-
} else {
534-
worker_close_and_free_connection(c);
535-
}
526+
} else if (!c->headers_sent && c->state != CONN_CLOSING) {
527+
/* Send 503 if headers not sent yet (no data ever arrived) */
528+
http_send_503(c);
529+
} else {
530+
worker_close_and_free_connection(c);
536531
}
537532
continue; /* Skip further processing for this connection */
538533
}

0 commit comments

Comments
 (0)