question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Polling stops on error

See original GitHub issue

I’m currently trying to set up a polling process to check the status of a long operation, here’s some example code:

const waitForCompletionQuery = gql`
query WaitForCloneCompletion {
  operationStatus {
    isCompleted
  }
}
`;

async function waitForCompletion(apolloClient) {
  const query = apolloClient.watchQuery({
    query: waitForCompletionQuery,
    forceFetch: true,
    pollInterval: 5000
  });
  let subscription;
  try {
    await new Promise((resolve, reject) => {
      const observer = {
        error: (err) => {
          if (isOKError(err)) {
            // Alert the user to the error and keep trying
            showErrorToast(err);
          } else {
            reject(err);
          }
        },
        next: (result) => {
          if (result.loading) return;
          const status = result.data.operationStatus;
          if (status.isCompleted) {
            resolve();
          }
        }
      };
      subscription = query.subscribe(observer);
    });
  } finally {
    if (subscription) {
      subscription.unsubscribe();
    }
  }
}

Some errors would be considered “OK” (like network errors, which probably makes this at least somewhat related to https://github.com/apollostack/apollo-client/issues/270) - while I need to make them known to the user, I should keep polling. Others indicate an operation failure and I should stop polling because it’s not going to change.

I would expect the above code to behave in that way, returning a promise that resolves on the first isCompleted value or rejects on the first non-OK error, but what actually appears to happen is that the polling just stops after the first error, and won’t start back up even if I explicitly call query.startPolling(5000) or subscription = query.subscribe(observer) after showErrorToast().

Is this user error or something odd in Apollo?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
danimancommented, Mar 7, 2017

@helfer can we bump this? 😃

For transient errors that are acceptable while polling, like network errors, it’d be nice if AC continued to poll and handled those errors elegantly. For cases where you’d want to display a network error toast or something, we could expose the state/error on the network status that indicates that the query is not actively polling successfully.

4reactions
dallonfcommented, Jan 11, 2017

My expectation of default behavior is that polling would go on forever until explicitly stopped (which in most higher-level usage, happens when the subscribed component unmounts), so I would also expect the error callback to be called for each new error (although it would also make some sense if it only was called for different errors, like next is only called for new data).

But if the behavior of automatically stopping a poll on error was considered expected and documented, then the ability to re-subscribe would definitely unblock my use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve ''Event Polling Stopped'' errors in Alarm ...
This can be done in SQL Server Management Studio by right-clicking on the AccessControl database and then selecting Properties > Files. Verify ...
Read more >
How to continue polling with observable interval if error occurs
The problem I have is that if in the middle of polling one of the network API calls fails, the polling stops. Ideally...
Read more >
[JENKINS-64800] After build failure, polling stops with "P4
Description. Sometimes when a job fails, it will stop polling Perforce for new changes and need to be manually kicked. This obviously greatly ......
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client helps you handle these errors according to their type, enabling you to show appropriate information to the user when an error...
Read more >
Incuity Client stops polling TOP Server (Error 0x80004002)
Incuity Client stops polling TOP Server (Error 0x80004002). Updated 04/17/2019 02:57 PM. We are using Incuity as an OPC Client to access data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found