vuestorefront/magento2

Socket timeout slower response

henkspane opened this issue · 9 comments

What is your question / Please describe your issue

What is your question / Please describe your issue
We are performing requests using GraphQL queries by Apollo. When a query response is slow (+-10 seconds), the storefront will throw a socket timeout error. Example:

[VSF][error]: [Network error]: FetchError: request to https://test.environment.example/graphql?query=query+categoryList%7Bcategories%7Bitems%7Bchildren%7Binclude_in_menu+is_anchor+level+name+position+product_count+uid+url_path+url_suffix+children%7Binclude_in_menu+is_anchor+level+name+position+product_count+uid+url_path+url_suffix+children%7Binclude_in_menu+is_anchor+level+name+position+product_count+uid+url_path+url_suffix+__typename%7D__typename%7D__typename%7Dproduct_count+name+uid+__typename%7D__typename%7D%7D&operationName=categoryList&variables=%7B%7D failed, reason: Socket timeout

The socket timeout is a problem in local environments.

I am not able to see a global configuration setting in Vue storefront for changing the default socket timeout for all queries. Is there a way to do this?

What version of Magento 2 Integration are you using?

1.0.1

Code of Conduct

  • I agree to follow this project's Code of Conduct

packages/api-client/src/helpers/magentoLink/graphQl.ts:21

Need to add params for timeout. Default is 15sec.
For example,
const agent = new HttpsAgent({
keepAlive: true,
freeSocketTimeout: 60_000,
});

Docs,
https://www.npmjs.com/package/agentkeepalive/v/4.0.0?activeTab=readme#new-agentoptions

@sequensucks We use Apollo and have only the following file: node_modules/@vue-storefront/magento-api/lib/helpers/magentoLink/graphQl.d.ts:

import { ApolloClient, ApolloLink } from '@apollo/client/core';
import { Config } from '../../types/setup';
export declare const apolloLinkFactory: (settings: Config, handlers?: {
    apolloLink?: ApolloLink;
}) => ApolloLink;
export declare const apolloClientFactory: (customOptions: Record<string, any>) => ApolloClient<import("@apollo/client/core").NormalizedCacheObject>;

I do not understand how we can use the configuration you mentioned.

@henkspane you're looking into 'declaration file' that is generated and available in your node_modules. File mention by @sequensucks is available in VSF Magento package. If you've generated VSF website with the CLI you don't have it in your project but only reference in node_modules.
So clearly you looking in wrong place.
The issue itself is related to the connection between VSF and Magento, that is taking too long.

The timeout seems to be much shorter than 15s – perhaps 7-8s. It is short enough that legitimate requests (place order) are affected.

Are there any workarounds available?

Has anyone found any solution to this problem? We are using version 1.1.0 and facing the same issue, there is a timeout of around 8s for requests from VSF to Magento

Edit: I have managed to fix it by adding the following code in middleware.config.js -> inside integrations.magento.customApolloHttpLinkOptions
fetchOptions: { timeout: 20_000, },