-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Currently fasthttp.RequestCtx implements context.Context nominally.
For performance reasons: Done() and Err() are essentially nop (With exception that if Server shuts down, channel will get closed).
In #965 (comment), @erikdubbelboer mentions that in between the time of reading the request from the connection and writing to the response (after Handler returns), nothing is done to the connection, hence we can not know when the client has closed the connection.
You incorrectly state that net/http works the same way.
In the browser, it is not uncommon to call a search endpoint when a user types text into a searchbox. As the user keeps typing text, it is not uncommon to cancel the prior request and fire another request to the search endpoint: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
I think fasthttp can implement a setting in RequestCtx that can be activated for a given endpoint only (eg search endpoint), that when activated, behind the scenes does a poll of the connection.
It checks at regular small time intervals by attempting to read from the connection. If the read fails, we know the connection was closed, and the done signal can be sent. (OR even more radical, we depart from context.Context guidelines and we set the Err() to non-nil and ignore adding a done channel)
We also document what is happening behind the scenes and explain that there will be a slight performance hit. It is opt-in.