describe

Share of this article is 19 years of time, have a real problem, the interface is a time-consuming micro service request, need back-end library table LianZha and check, more so than the general interface request time is long, may be more than two minutes, and then end at self-test the postman self-test, the success is just a long time, However, the front end will be directly disconnected due to timeout, and finally the two sides will not be able to dispute. I conducted a further study on this part and drew some conclusions for everyone to share.

Differences in different requests

At present, the front-end request uses SPA as an example. If the webpack build tool is used, the development server is provided by webpack-dev-server, dev-server uses Express internally, and Express uses require(‘ HTTP ‘) internally. If http-proxy-middleware uses a node-http-proxy library internally, it’s essentially require(‘ HTTP ‘). The solution is to set proxyTimeout or timeout, see github.com/chimurai/ht…

After a request is made on the front end, the request is actually made through the browser kernel, because the request is essentially an XHR request, and the Chrome kernel writes the request in 5 minutes.

So how does the backend self-test pass the self-test? There are two types of self-test in the backend. One is to use the local code to perform a single test, which must have no timeout limit unless JDBC or the code itself is gg, and the other is to use swagger and Postman, which can have no timeout control. So these two mock requests cannot completely reproduce the error of the front-end request timeout.

The actual situation

Actual situation, I found that the problem is not just here, also is after the termination of the gateway, but the gateway is limited due to technology can’t distinguish between setting the difference of each interface length, even if the front end of the request the length, and let go to 5 minutes, also because the backend gateway unified set the request time lead to return to the interface timeout problems.

Final solution: 1 the backend support on interface performance, shorten the request 2 back-end provide multiple gateways, when it comes to the long time interface, using the difference of the gateway to request 3 front for long long interface, no gateway, IP + port instead of request, can avoid because gateway timeout problems caused by set the timeout

Stretch thinking: Take one more step out

When a problem occurs, wanting each function to think outside its own boundaries about why it happened, rather than why I’m right, doesn’t help. When problems occur, we should consider the following questions or directions:

1 isn’t other people’s way and what is the difference between 2 is yourself what is the blind spot, how can lead to the question 3 repetition appear to other people’s problems, especially under the environment of his or her own machine or 4 when problems occur, comfort each other’s feelings, then can see in their own way or the other remedy, Ask the other party to solve the dilemma at this time. 5. After finding out the cause and solution, review the whole process and extend it to the department or company’s specifications to maximize the value

The original address: www.yuque.com/robinson/wo…