Fix buffered upload handler not cancelling on client disconnect (#6307)
* Fix buffered upload handler not cancelling on client disconnect When a client disconnects during a buffered file upload, the enqueued event handler was not being cancelled, leaving orphaned tasks. Add disconnect detection to _UploadStreamingResponse (via ASGI 2.4 receive watcher and ClientDisconnect handling) and propagate an on_task_future callback through enqueue_stream_delta so the upload path can cancel the EventFuture when the connection drops. * Update packages/reflex-components-core/src/reflex_components_core/core/_upload.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update packages/reflex-components-core/src/reflex_components_core/core/_upload.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Generalize disconnect-cancel for streaming event responses Move disconnect detection out of upload-specific code into a reusable DisconnectAwareStreamingResponse in reflex-base. Drop the on_task_future callback from enqueue_stream_delta — the generator"s finally block already cancels the task future when the body iterator is closed on disconnect. * Add pre-2.4 streaming response disconnect test, remove bogus event processor tests Add test coverage for the pre-2.4 ASGI disconnect path in DisconnectAwareStreamingResponse. Remove test_stream_delta_aclose_cancels_in_flight_event and test_stream_delta_consumer_task_cancellation_cancels_in_flight_event — they passed with or without the task_future.cancel() fix because _on_future_done already cascades cancellation from the EventFuture to the handler task. --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
F
Farhan Ali Raza committed
55191baae4dee2a38cf0650bd825217067c0e6b4
Parent: 9680808
Committed by GitHub <noreply@github.com>
on 4/9/2026, 11:54:29 PM