When a query has to return more data, Salesforce uses Query Locators. In order to understand more about thishttps://infallibletechie.com/2018/10/what-is-query-locator-in-salesforce.html
Reasons may be below for the exception
1. Too much data for a single query. Try to limit the data.
2. You’ve exceeded your allowance of having max 5 queryLocators open.
3. You’ve exceeded 10 minute inactivity timeout of a queryLocator.