How an Async Thread Pool Exception Caused Service Chaos

Recently, I encountered a very strange service restart issue in our business, and the troubleshooting process was quite complex. This article will review the process. The problem involves multiple aspects such as C++ thread pools, integer overflow, exception catching, and blocking, which is quite interesting.

Next, I will organize the content of this article according to the problem investigation process, starting with an introduction to the problem background, then listing the initial troubleshooting ideas and methods for locating abnormal requests. Then, through code analysis and some simple use cases to reproduce the problem, we will unveil the mystery of the service restart.

Read More

Understand Web Stream Output Implementation with Examples

If you’ve used large language models like ChatGPT, you may have noticed that the AI’s output text appears in “bursts” during chat conversations. This is known as stream output. How is this effect achieved in the browser?

This article will introduce 4 common methods to implement stream output effects, each demonstrated with practical examples. The choice of method in business applications depends on specific requirements and scenarios.

  1. Client-side polling: The client sends requests to the backend service at regular intervals (e.g., every few seconds) to retrieve new data.
  2. Chunked transfer: Supported by HTTP/1.1, the server can send only part of the response content at a time, and the client can start processing as soon as it receives partial data.
  3. Server-Sent Events: The server pushes information to the browser. The browser creates a one-way connection to the server, through which the server can send multiple messages.
  4. WebSocket: Establishes a persistent, full-duplex connection, allowing real-time, two-way communication between the server and client.

Read More

Dive into C++ Object Memory Layout with Examples

In the previous article Analysis of C++ Process Coredump Problem Caused by Missing Bazel Dependencies, due to the use of different versions of proto objects in the binary, inconsistent object memory layouts led to memory address chaos when reading and writing members, ultimately causing the process to crash. However, we didn’t delve into the following questions at that time:

  1. How are objects laid out in memory?
  2. How do member methods obtain the addresses of member variables?

These actually involve the C++ object model. The book “Inside the C++ Object Model” comprehensively discusses this issue and is well worth reading. However, this book is not easy to read, and some content can be difficult to fully understand without practice even after reading. This article attempts to start from practical examples to help everyone gain an intuitive understanding of C++ class member variables and functions in memory layout, which will make it easier to understand this book later.

Read More