The timeout that you added is for the HTTP connection, not for the DB connection. Therefore, if your database query takes more than the timeout (15 sec by default if I am not mistaken), the query will timeout. Could that be the problem?
In that case, you could increase the query timeout like @jola wrote here: How do I avoid DB disconnect on chunked streaming of large amount of data?
That said, having a very long running DB query might not be ideal, so getting the records from the DB in chunks might be a better option.