Avoiding Common Concurrency Bugs in Go

In the paper Understanding Real-World Concurrency Bugs in Go, several researchers analyzed common concurrency bugs in Go and validated them in some of the most popular Go open-source projects. This article organizes the common bugs mentioned in the paper and provides an analysis of solutions. The paper categorizes bugs into two types: blocking and non-blocking: Blocking: A goroutine gets blocked and cannot continue execution (e.g., deadlock). Non-blocking: Execution is not blocked, but there is a potential data race (e.g., concurrent writes). Blocking Bugs Blocking bugs have two root causes: shared memory (e.g., getting stuck on a lock operation intended to protect shared memory) and message passing (e.g., waiting on a channel). The study found that the number of bugs caused by shared memory and message passing is comparable. However, since shared memory is used more frequently than message passing, it was concluded that shared memory is less likely to lead to bugs. ...

August 17, 2021 · 5 min · Zhiya

Issue with ORDER BY Not Working in MySQL Subqueries

By chance, I discovered that an SQL statement produced different results when executed on different MySQL instances. Problem Description To simulate a business scenario, we create two tables: product_tbl for products and product_operation_tbl for product operation records. The structure and data are as follows: Next, we need to query the latest modification time for all products using the following statement: select t1.id, t1.name, t2.product_id, t2.created_at from product_tbl t1 left join (select * from product_operation_log_tbl order by created_at desc) t2 on t1.id = t2.product_id group by t1.id; From the results, we can see that the subquery first sorts all records in product_operation_log_tbl in descending order by creation time (created_at), then performs a join with product_tbl, thus retrieving the latest modification time for the products. ...

July 29, 2021 · 3 min · Zhiya

One-Click Proxy Setup for WSL2

Cloning a large git project in the WSL2 environment can be slow without a proxy, so I explored how to route WSL2 through Windows’ proxy client. Differences in Networking between WSL1 and WSL2 In the WSL1 era, since the Linux subsystem and Windows shared network ports, accessing Windows’ proxy was straightforward. For instance, if the Windows proxy client was listening on port 8000, you could simply execute the following command in the Linux subsystem to route requests through the proxy: ...

June 30, 2020 · 2 min · Zhiya

WSL2 Installation Guide for Developers

Why Use Windows for Development For a long time, macOS has been favored by programmers for its Unix-like features. However, in recent years, Apple has rarely introduced groundbreaking hardware products. The removal of the Esc key, the use of butterfly keyboards, almost zero hardware upgradability, and tightened system permissions have made Macs less suitable for programming than before. On the other hand, the PC ecosystem has maintained software openness while its hardware experience has gradually caught up with or even surpassed Macs. I no longer want to use a Mac for development and a PC for gaming; I hope to use one computer for both gaming and development, so I’ve returned to the PC camp. ...

June 1, 2020 · 6 min · Zhiya

Issues Arising from Cross-Process Use of gRPC

Problem Description When using gRPC for communication in a Python project, issues such as blocking or errors can occur when used across processes (the symptoms vary depending on the version of gRPC.io). The following code demonstrates a cross-process usage demo where the main process sends requests to a gRPC server on port 30001, and the child process also sends requests to the same server. def send(): channel = grpc.insecure_channel('localhost:30001') stub = message_pb2_grpc.GreeterStub(channel) response = stub.SayHello(message_pb2.HelloRequest(name='you')) print(f"Greeter client received 1: " + response.message) def main(): channel = grpc.insecure_channel('localhost:30001') stub = message_pb2_grpc.GreeterStub(channel) response = stub.SayHello2(message_pb2.HelloRequest(name='you')) print("Greeter client received 2: " + response.message) p = multiprocessing.Process(target=send) p.start() p.join() if __name__ == '__main__': main() When using gRPC.io version 1.28.1, an error occurs: the main process can receive the server’s response normally, but the child process reports Socket operation on non-socket. ...

April 23, 2020 · 4 min · Zhiya