I am now working in a medium-sized Internet enterprise. The salary and treatment I got at the end of last year are very good, but to sum it up, it is the hope of the whole village. At worst, it is almost a project team. Here is one of my project fire fighting experience (carry the pot experience). After the year, a cooperative company launched a sub-business system to connect with the company’s internal single point system. I received the technical advice from the company: after the project was started, I could not log in regularly. After the restart, I could not log in again after a short period of time. The technical staff of the other party was confused about the reason, and there was no error information in the background log. I was ordered to put out the fire in the project. In fact, it took me 5 days to solve the problem that could have been solved in 2 days. I’ll explain the reasons one by one.

1. Not mastering the essence of log

Log The debug, INFO, and error information of logs are randomly typed. The debug information is info, and the debug information is…… The result is a successful login request. 300 lines of code are typed in the background log, which seriously affects the efficiency of troubleshooting and tracking problems. The project online log level is still debug, but changed to INFO, and many key information is not printed as a result.

Key information about the log output format is incomplete. The category name of the log, the thread in which it occurred, and the number of lines in the code are not clearly shown, and where the log was printed is unknown.

Here, I want to say that no matter how many frameworks there are, the configuration of various upper frameworks such as Spark, Flink, Hadoop, messaging-ware and so on is only a matter of fancy. Log log is an internal function, which is a means to quickly solve various online problems in the future.

Here is his log output:



2. Core parameters are not judged

Method returns data without null or “” string judgment, resulting in null pointer exceptions in various cases. The functions of the project are all idealized. I just need these data to give you the correct results, otherwise I don’t know what went wrong. This problem caused me great confusion when I restored the scene of the case. I accidentally made a null pointer error, and I had to strengthen the judgment and processing of this error, so that I could simulate the situation that I could not log in after logging in for many times.

In addition, the use of IN in the SQL statement in the project is not standard. Combined with the previous NULL judgment, there is a kind of :” Hey, I used this account to log in successfully, the SQL is correct, use this person’s account to log in, why the SQL syntax is incorrect, obviously call the same block of code ah.”



It is obvious that the syntax of this SQL statement is problematic if the roleID is a “‘ string.

3. Local variables are promoted to static variables

This is the reason for the question raised at the beginning of this article. Because login authenticates the user’s identity to a single point system, it uses the HttpClient framework to send HTTP requests. It takes the httpClient variable as a static variable and then reuses the object in the method. Then finish method calls inside the object and does not release resources reasonably close, this framework can maintain a connection pool by default, if your application is not released after a resource usage, the resource will not be used by the next request, a new request must be waiting in the queue, and then when a user logs in 20 times, the request in the resource pool are used up, New requests cannot obtain resources and are kept waiting in the waiting queue. As a result, the server times out and login fails. Error 504.

When I saw this class static variables when httpClient, I had a bad feeling, here is a prone to error, if I, the framework, this class is not fully grasp, I will it into local variables, so in low concurrency, let GC to help me recycle it.



After transforming:



4. Interceptor path planning is chaotic

This problem has also caused obstacles for me to troubleshoot problems. To troubleshoot login problems, I first need to trace the method track of the back end after a successful login to find out which link is the code problem, because there is no task error information. As for his interceptor, one login request was successful and the interceptor repeated three times. At least once in the process, the interceptor didn’t do anything valid. The problem was caused by his front-end business sending irrelevant requests that were intercepted. Gives me the opportunity to review the code and find a problem with the section of code that calls HttpClient.

5. Misuse of try catch

This code is also disgusting, because it suddenly wraps a try catch. Gee, this guy is good, and also performs special marking for some exceptions. I take a close look at the code, and what is this? So fierce will abnormal eat, clearly there is a problem, it does not report, through it to trigger a new anomaly to hide the real problem.

Finally, I want to say, programmers why bother programmers, code left a line, good to meet what in the future. You also don’t want to dig a hole for yourself, can’t solve it, and then say, “Big brother, are you busy? I have a small problem here, help check it.”

If the Java microservices, distributed, high concurrency, high availability, large Internet architecture technology, interview experience exchange. If you are interested, you can follow my wechat official account, where I will release free information links from time to time. These materials are collected and sorted out from various technical websites. If you have good learning materials, you can send them to me privately, and I will indicate the source and share them with you. Welcome to share, comment and forward.