vuestorefront / magento2

Vue Storefront 2 integration for Magento 2
https://docs.vuestorefront.io/magento
MIT License
171 stars 119 forks source link

Socket timeout slower response #1368

Open henkspane opened 2 years ago

henkspane commented 2 years ago

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

sequensucks commented 2 years ago

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

henkspane commented 2 years ago

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

KrisRogozinski commented 2 years ago

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

JesseMaxwell commented 1 year ago

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?

andreiRC1 commented 11 months ago

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

simonmaass commented 3 months ago

We are also seeing this error on a couple of order placements!

JesseMaxwell commented 3 months ago

For what it's worth, I think this is a major bug especially since there is no known workaround.

simonmaass commented 3 months ago

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

This worked for us

Muhammad-Usman073 commented 1 week ago

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

Thanks for the tip! dude 🤲