When is the query limit applied?

Hello
when specifying the query limit (the limit the number of logs lines returned), is it applied at query-frontend or at querier pods level?
For example having a big dataset of logs line, and trying to run a query like:
{mylabel1=myvalue1} |=error
this extract a lot of data, but we are interested only on first 1000 lines of the result.
When the cut of unnecessary lines is applied? I mean would the queriers stop loading new chunks when first 1000 lines are collected?
We are asking this question because running query for 1h it was completing correctly while running for 6h of time range the following error is logged on the querier:

{"caller":"batch.go:720","err":"failed to get s3 object: RequestCanceled: request context canceled\ncaused by: context canceled","level":"error","msg":"error fetching chunks","org_id":"977e784f-e3db-4905-9cc0-ed72f1a6d831","ts":"2023-05-02T12:51:01.868428045Z"}

Thanks for your help