magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Socket timeout slower response

Open henkspane opened this issue 3 years ago • 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

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

henkspane avatar Sep 29 '22 08:09 henkspane

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 avatar Oct 18 '22 09:10 sequensucks

@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 avatar Oct 18 '22 13:10 henkspane

@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.

KrisRogozinski avatar Nov 07 '22 09:11 KrisRogozinski

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?

JesseMaxwell avatar Apr 27 '23 13:04 JesseMaxwell

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, },

andreiRC1 avatar Dec 11 '23 09:12 andreiRC1