agisboye / app-store-server-api

A Node.js client for the App Store Server API
MIT License
210 stars 32 forks source link

Occasional timeout on getSubscriptionStatuses #26

Closed previouslysahil closed 1 year ago

previouslysahil commented 1 year ago

Hi there! I previously was not encountering this issue so I am wondering if this is a current problem with Apple's sandbox server, not sure. Currently when using the AppStoreServerAPI with a sandbox environment, while calling await api.getSubscriptionStatuses(originalTransactionID); every now and then this call will timeout for over 60 seconds. This in itself is confusing because the call will work once or twice and then timeout the next time and then work etc.

I am currently using the AppStoreServerAPI inside a Firebase cloud function which will cancel the function execution after this 60-second timeout. This timeout functionality is triggering because there is no return from the await api.getSubscriptionStatuses(originalTransactionID); in this 60 second time period.

As I stated above I am only noticing this issue now (first on 0.7 but I have since upgraded to 0.9 and the issue still persists) although while testing this functionality a few weeks ago everything was working fine. I have made no changes to my cloud function code within these few weeks so my assumption is that there is an issue with either the API or Apple's sandbox server at the current moment.

I have not tested using the production environment yet (I'm still very new to Apple's subscription framework, and not sure about the implications of using prod vs sandbox for testing). Yeah anyways, so not sure if this is truly an issue with this API but I thought I would bring it to your awareness anyways (could also just be me problem since as I mentioned I'm pretty new to all this subscription stuff in Node js).

Here is a code snippet I'm using this function in.

export const sendIOSSubscriptionInfoSandbox = functions.https.onCall(async (data, context) => {
    // Some authentication code above this
    try {
        functions.logger.warn("Entering updateIOSSubscriptionInfo");
        await updateIOSSubscriptionInfo(originalTransactionId, sandboxAPI, false);
        functions.logger.warn("Finished updateIOSSubscriptionInfo");
    } catch (error) {
        functions.logger.error("Error sending iOS subscription info:", error);
        throw new functions.https.HttpsError("permission-denied", `Error: ${error}`);
    }
});
async function updateIOSSubscriptionInfo(originalTransactionId: string, api: AppStoreServerAPI) {
    // Use fetch subscription to get subscription info
    functions.logger.warn("Entering api.getSubscriptionStatuses");
    const response = await api.getSubscriptionStatuses(originalTransactionId);
    functions.logger.warn("Finished api.getSubscriptionStatuses");
    // Other code using response beneath this
}

During the occasional function calls where api.getSubscriptionStatuses() fails the "Finished api.getSubscriptionStatuses" warning will never trigger and the catch block in sendIOSSubscriptionInfoSandbox will also never trigger which leads me to believe api.getSubscriptionStatuses() is timing out.

agisboye commented 1 year ago

Hi previouslysahil, This sounds like an issue with Apple's sandbox server or the Firebase environment in which your code is running. We could add an option to set the request timeout to something lower than 60 seconds but it won't solve the underlying issue.

previouslysahil commented 1 year ago

Hi! Thanks for the quick response, awesome I wasn’t sure but just thought I’d bring it up with you anyways to confirm. Awesome API by the way!