Skip to content

resultHandler called twice #3517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mlight3 opened this issue Feb 25, 2025 · 2 comments
Closed

resultHandler called twice #3517

mlight3 opened this issue Feb 25, 2025 · 2 comments
Labels
bug Generally incorrect behavior needs investigation

Comments

@mlight3
Copy link

mlight3 commented Feb 25, 2025

Summary

I wrapped fetch method with withCheckedThrowingContinuation, but I got a fatal error.

Thread 1: Fatal error: SWIFT TASK CONTINUATION MISUSE: fetch(_:ignoreError:cachePolicy:) tried to resume its continuation more than once, throwing cannotParseResponse!

Fortunately, cannotParseResponse error is used in only one place so I can easily tracked it.

resultHandler was called from below two method.

Image Image

Version

1.15.1

Steps to reproduce the behavior

I couldn't share the response data because it is private project in company. Sorry about it.

Logs

Anything else?

No response

@mlight3 mlight3 added bug Generally incorrect behavior needs investigation labels Feb 25, 2025
@BobaFetters
Copy link
Member

The result handler being called multiple times is expected behaviour. In the specific example you provided, internally the URLSessionDataDelegate method urlSession(_ session, dataTask, didReceive) can be called more than once and provides chunks of data as received, so this is then passed through the completionBlock every time new data is received. Separately the error delegate method could be called at anytime during the request if an error is encountered. When handling the response data and result handlers you will want to handle it similar to how you would handle if you were directly implementing these delegate methods which can be called more than once.

There has been some discussion around this and supporting Swift Concurrency, specifically you may be interested in this comment.

Another note is we are currently working on our 2.0 release which will support Swift Concurrency in the library, you can follow along with that here.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior needs investigation
Projects
None yet
Development

No branches or pull requests

2 participants