microsoft / typed-rest-client

Node Rest and Http Clients with typings for use with TypeScript
Other
675 stars 118 forks source link

ETIMEDOUT for certain calls on Node 16 #306

Closed mmajcica closed 2 years ago

mmajcica commented 2 years ago

Environment

Node version: v16.13.1 Npm version: 8.1.2 OS and version: Windows 10 1909 typed-rest-client version: 1.8.6

Issue Description

Getting a timeout on certain calls.

Exception: Error: connect ETIMEDOUT 13.107.42.20:443 Stack: Error: connect ETIMEDOUT 13.107.42.20:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17).

Expected behavior

I'm making a call to Azure DevOps REST API. Calls generally do succeed, until I make a pagination call. Then it times out. The same call made with Postman, curl, or via web browser does succeed.

Example call 1 that runs correctly

    let url = `${orgUrl}_apis/projects?api-version=6.0`;
    const basicAuthHandler: BasicCredentialHandler = new BasicCredentialHandler("", token, true);
    let httpClient = new HttpClient('test', [basicAuthHandler]);

    let res1 = await httpClient.get(url);

Now, I do request the same resource but with the continuation token specified and it fails.

    let url = `${orgUrl}_apis/projects?continuationToken=100&api-version=6.0`;
    const basicAuthHandler: BasicCredentialHandler = new BasicCredentialHandler("", token, true);
    let httpClient = new HttpClient('test', [basicAuthHandler]);

    let res1 = await httpClient.get(url);

The same goes if I do use at example "azure-devops-node-api" library which if I'm not wrong is underneath using typed-rest-client:

    let authHandler = azdev.getPersonalAccessTokenHandler(token); 
    let connection = new azdev.WebApi(orgUrl, authHandler);  

    let coreApi = await connection.getCoreApi();

    let projects = await coreApi.getProjects();

    let projects2 = await coreApi.getProjects(undefined, undefined, undefined, "100", undefined);

First GetProjects() invocation on this example returns data, second one times out.

It seems that this has to do with the version of node we are using. If I run the same examples with node 10, it all works as expected. Can you confirm or think of the reason why this is happening or is there a workaround?

Thanks

EzzhevNikita commented 2 years ago

@mmajcica This definitely could be the problem caused by Node 16, this library is mostly used as a rest client for the Azure DevOps in the-box-tasks and supported to correspond tasks use cases, most of the tasks are running with Node 10, so from our side I can exactly say that this library is correctly working with Node 10. Regarding running it with Node 16, truly speaking I don't know if anybody in the team ever tried running this lib with Node 16. I can exactly say that we couldn't guarantee correct work on this Node version, since such a use case has never been tested.

mmajcica commented 2 years ago

@EzzhevNikita we are trying to move to node16 and push our code on Azure Functions v4. Both azure-devops-node-api and typed-rest-client are essential for our code and this is not great news. Any plans to test and support at least node 14?

mmajcica commented 2 years ago

I also tried with v14.17.0 but still the same outcome.

mmajcica commented 2 years ago

@EzzhevNikita so node10 is still actual but MS is pushing us to get on newr version on the other side, check the Q1 feature line for Azure DevOps agents https://dev.azure.com/mseng/AzureDevOpsRoadmap/_workitems/edit/1888423 Deprecate Node 10 from agent and tasks https://docs.microsoft.com/en-us/azure/devops/release-notes/features-timeline

Not sure how to proceed anymore :/

mmajcica commented 2 years ago

I found the culprit. It has to do with a typo inside the NO_PROXY env var used. Though this solves the issue, I would expect that such a typo would not cause such wired issues. This should be investigated, however not by you, but with nodejs community.