Fix resource leak in query queue

Queries can transition to the CANCELED state before they are started. In
particular, this happens if a user cancels their query while it is
queued. In this case, the state change listener is never called, because
the query is already finished, and this leaks one slot in the query
queue.