When a query has to return more data, Salesforce uses Query Locators. In order to understand more about this, check the following link:
http://www.infallibletechie.com/2018/10/what-is-query-locator-in-salesforce.html
Reasons may be following 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.