OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 96 forks source link

Excel Custom Functions: API Calls Timing Out After 60 Seconds #1184

Open dho-caissa opened 4 years ago

dho-caissa commented 4 years ago

Current Behavior

The excel custom functions created as part of Add-In seem to have 60 seconds request limit on API call. When API call takes more than 60 seconds, it return "Network Request Failed" error. We are experiencing this 60 seconds request time limit in our current production Excel Add-In. Is there way to change it in Excel or Excel Add-in?

Steps to Reproduce, or Live Example

To demonstrate the 60 seconds timeout behavior, we created a demo project with two custom functions. One function calls a data service that takes 70 seconds to complete. The other function calls a data service that takes 5 seconds to complete. The first function failed with "Network Request Failed" error. The code for demo project can be found here. The readm.md has instructions how to run it. https://github.com/dho-caissa/ExcelAddinDemo. The excel custom function seems have a timeout limit on fetch() call.

Demo code to show the behavior: ` try {

    const path = 'https://localhost:44360/data/GetDataFailed';

    const response = await fetch(path);

    const text = await response.text()

    const json = JSON.parse(text);

    if (json === null || json === undefined) {

        return "#no data";

    } else {

        return json;

    }

} catch (err) {

    return "#exception:" + err;

}

;`

Your Environment

xiaochunms commented 4 years ago

Thanks for the effort for the demo project. I tried the demo project, but I hit the error in the very first step, i.e. Run "NPM install and Yarn install". Any suggestion to unblock here and I can move forward then?

image

dho-caissa commented 4 years ago

hi @xiaochunms, try run "NPM install" first. Then, run "yarn install". thanks

xiaochunms commented 4 years ago

@dho-caissa I got following error when run "yarn install". :( image

dho-caissa commented 4 years ago

@xiaochunms I think NPM install should be enough to get the javascript packages. You don't need to run the "yarn install" if you don't have yarn installed. The main code to demo the behavior is here. The code simply calls the API and it is relatively straight forward. thanks again. https://github.com/dho-caissa/ExcelAddinDemo/blob/master/src/Caissa.ExcelAddin/CustomFunctions/src/functions.ts "function getFundMarketValueFail" calls api that takes more than 60 seconds. It fails with "Network Request Failed" error.

dho-caissa commented 4 years ago

@xiaochunms is there any update? Any suggestion? Thanks

dho-caissa commented 4 years ago

Hi, Is there any update on the 60 seconds timeout rule? We tested Fetch and XmlHttpRequest with the Microsoft sample project (link below). When API takes more than 60 seconds, both methods call failed. thanks
https://docs.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-web-reqs

pbl2108 commented 4 years ago

@xiaochunms, @RuoyingLiang do you have any update on this? It is really causing us problems.

RuoyingLiang commented 4 years ago

The issue is under investigating. @shaofengzhu , could you help to update the thread once there are more information?

pbl2108 commented 4 years ago

@shaofengzhu could you please let us know if there is an update on this?

zlatko-michailov commented 4 years ago

Thanks for adopting custom functions! I am sorry to see you've had an unresolved issue for such a long time.

Before I investigate any further, please take the following steps, and let me know of the outcome:

  1. In Excel, click on Insert > Get Add-ins.
  2. Select the Store tab, if you are not already there.
  3. Enter WA104381720 in the Search box, hit Enter, and click the Add buttons as necessary to install this add-in.
  4. Back to the grid, enter these formulas in any 4 cells:
    • =MICROSOFT.OFFICE.TEST.UPGRADE.CONST_DELAYED(120000)
    • =MICROSOFT.OFFICE.TEST.UPGRADE.CONST_DELAYED(75000)
    • =MICROSOFT.OFFICE.TEST.UPGRADE.CONST_DELAYED(60000)
    • =MICROSOFT.OFFICE.TEST.UPGRADE.CONST_DELAYED(30000)

The argument is the number of milliseconds the function will delay the reporting of its result. So you'll have to wait for at least 2 minutes for all of them to finish.

Please report here what happens after 2 minutes.

Thanks, Zlatko

JunielKatarn commented 4 years ago

This issue has been identified as a hard-coded timeout in our JavaScript HTTP client. Work in progress to increase this limit, or make it configurable.

pbl2108 commented 4 years ago

@zlatko-michailov (мерси много!) thank you so much for looking into this!

I ran the functions with the 4 parameters you suggested and they all returned 42 as shown on the screenshot. I am not sure if they are making HTTP calls to a server, or the specified delay is completely happening on the client, because the issue we are experiencing with functions that make HTTP calls that take more than 60 seconds.

image

zlatko-michailov commented 4 years ago

@pbl2108, it's my pleasure to help you adopt custom functions.

My add-in is very simple. It only leverages the core custom functions pipeline. I wanted to prove that the pipeline has no time limit.

@JunielKatarn is from the team that owns the networking API on top of the ReactNative runtime. He'll take it from here.

Alternatively, you can also try a "shared runtime" which uses a real browser. See if it has the same issue. All you have to change is add an element to your manifest as described here: https://docs.microsoft.com/en-us/office/dev/add-ins/reference/manifest/runtime. You can see an example here: https://github.com/OfficeDev/custom-functions/blob/master/addins/upgrade/upgrade_shared.xml

I'll keep monitoring this thread in case something related to the pipeline comes up.

pbl2108 commented 4 years ago

Thanks again @zlatko-michailov!

We tried the shared runtime at some point and we were not able to get it working successfully. I am not sure if the issue we ran into was the same limitation of 60 seconds, or something else. We will try again.

Excel functions defined with the JavaScript API are very powerful, and we have been using them since the early versions when they became available.

@JunielKatarn please keep us posted on the progress of removing the 60s limit or making it configurable, as this is the preferred solution for us.

JunielKatarn commented 4 years ago

@pbl2108 I have developed and submitted a fix in our JS runtime. It should be available in the next monthly Office update.

The timeout will be settable using XMLHttpRequest.timeout.

pbl2108 commented 4 years ago

That's great news @JunielKatarn! Thanks for addressing the issue. We will be on the lookout for the update.

oabdelkarim commented 2 years ago

Any updates on this!?

JunielKatarn commented 2 years ago

This issue was fixed over a year ago. Feel free to close.

sboudouk commented 2 years ago

It is not fixed at all.

Using either fetch or XMLHttpRequest which both have default timeout set to 0 (no timeout) will timeout within 60 seconds. Excel is doing something under the hood that create this behaviour.

I don't know if it is intended or not but judging by maintainers comments I'd say no.

The consistent and simple workaround is to set manually your HTTP Client Timeout to something higher than 60 seconds and NOT to 0.

Simply check XMLHttpRequest timeout documentation

A similar behaviour is possible with fetch api, just google it.

It would be great, even if it's unintended, to have it documented somewhere in Office add-in docs.

Thanks for your work.

JunielKatarn commented 2 years ago

@sboudouk can you please share the Office/Excel version you are using?

See https://support.microsoft.com/en-us/office/about-office-what-version-of-office-am-i-using-932788b8-a3ce-44bf-bb09-e334518b8b19

sboudouk commented 2 years ago

Sure.

Excel for Mac with a 365 subscription, version 16.64 (22081401)

Similar behaviour can be observed on latest versions of Windows / Office 365 Web.

To reproduce, just setup any server that answer after 60s + and request it from a shared runtime custom function through fetch or XMLHtttpRequest. I can share my very basic Express server that I use for test if needed.

JunielKatarn commented 2 years ago

Excel for Mac with a 365 subscription, version 16.64 (22081401)

I drove the Windows implementation only. Office uses React Native for its JS framework. The macOS version of the HTTP module is completely separate from the Windows one.

I'll reach out to the team owning the macOS variant.

If you also notice this on Windows, would you kindly also obtain that version number? I'll try to reproduce this behavior on my end.

sboudouk commented 2 years ago

Same issue on Windows, Microsoft 365 MSO Version 2207 Build 16.015427.20182 64-bit

JunielKatarn commented 2 years ago

Same issue on Windows, Microsoft 365 MSO Version 2207 Build 16.015427.20182 64-bit

This version contains the fix that makes the low-level HTTP client timeout configurable, with a value of 0 meaning not timeout. But, we have found a hard-coded 60 second timeout for CORS preflight requests (not the actual final request). However, this would not behave as you described (the manual timeout would not override this value):

The consistent and simple workaround is to set manually your HTTP Client Timeout to something higher than 60 seconds and NOT to 0.

We verified the lower-level components' timeout behavior, and setting it to 0 does succeed for regular (non-preflight) requests that take longer than 60 seconds.

Follow-up actions on our side:

sboudouk commented 2 years ago

Thanks, great actions. I'm sure this will help the next ones facing this issue.

guptamayank9827 commented 1 year ago

Facing the same issue on Microsoft for Excel for Mac v16.71 (23031200).

Works all good using excel online.

Using fetch to make API calls.

This is affecting our production excel add-in.

Would be very helpful if you have any updates / solution on the same?

b-g-d commented 8 months ago

This still seems to be an issue in Word for Mac as of Jan, 2024! @JunielKatarn , any way to learn more about progress on this?

JunielKatarn commented 8 months ago

@b-g-d I am not involved in Word for Mac development. The issue I worked on for Custom Functions was specific to Excel for Windows.

@shaofengzhu can you please help us route this issue?

timr11 commented 4 months ago

Hi, is there progress on this issue? I'm developing an Excel add-in on Mac Ventura 13.4 (22F66), Excel Version 16.84 (24041420), this is a major limitation. Would greatly appreciate this being addressed.

BjornBirkelund commented 4 months ago

This has also become a pressing issue for us, we are developing an excel add-in using react and are having our requests time out after 60s. Mac OS Sonoma 14.4.1 Version 16.85 (24051214) Microsoft 365 Subscription