Article List
I remember impulsively buying a tent last fall. Aside from setting it up once to check it out, it’s been sitting untouched ever since. The weather turned cold, and I never found the right opportunity to use it. The following weekends were busy with wedding photoshoots (I even ran a red light and lost six points on my license, so I haven’t driven since 😓), then there was a trip abroad, leave adjustments, the New Year, more leave adjustments, my sister starting school, my mom returning home, and days of continuous rain in between.
...
1. Background Recently, during a joint debugging session, I encountered a situation where a gRPC Server returned nil for a specific interface. Since the Server was functioning normally and the interface was implemented, there were no errors during the call. However, the program suddenly terminated without any log output. The issue was easily reproducible by simulating the return of nil data. In Debug mode, I could see the panic and the call stack information.
...
1$ pnpm add asar -g 2$ asar extract /[sourcePath]/app.asar /[targetPath]/ # Extract asar After extraction, the contents are as follows:
Unnecessary Locales: Remove unused language packs in the locales directory.
1// Set language pack before whenReady 2app.commandLine.appendSwitch('lang', 'en-US'); 3await app.whenReady() Dependencies: Ensure that development dependencies are not listed as production dependencies.
File Locking: If Electron-builder prompts that app.asar is occupied, close VS Code.
ogImage: https://image.coldcoding.top/file/AgACAgQAAyEGAASUgNIDAAOdZ-LLW2SY1yk2VuSGbtbqq3iEFT4AAgPGMRuknBlTlzRoYu-UvNoBAAMCAAN3AAM2BA.jpg
In Go, strings are immutable, meaning once created, their content cannot be modified. Therefore, each time you concatenate strings, a new string object is generated, which can have performance implications.
Common String Concatenation Methods Using the + Operator 1s1 := "Hello, " 2s2 := "world!" 3result := s1 + s2 Performance Analysis: Each use of the + operator creates a new string, allocating new space equal to the sum of the spaces occupied by the strings to be concatenated.
...
sync.Once is a type in the Go standard library’s sync package, designed to ensure that a specific operation is executed only once in a concurrent environment. It is commonly used for initializing resources or performing one-time setup operations, avoiding issues that arise from repeated execution.
Core Functionality The core method of sync.Once is Do, which has the following signature:
1func (o *Once) Do(f func()) The Do method takes a function f as an argument and guarantees that this function will be executed only once, even if Do is called multiple times.
...
Background There was a requirement to automatically switch to a certain interface, using Vue’s watch to listen to the gRPC connection state (subscription), and then calling an RPC interface to fetch a certain value. Occasionally, the value could not be retrieved, and the logs showed an Unavailable error: 1rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial tcp xxxx: connectex: No connection could
...
Background When starting the process, it occasionally crashes. If it doesn’t crash at startup, it won’t crash during subsequent operations. This narrows down the debugging scope. Below is part of the error stack information. It is clear that the crash is caused by concurrent map writes, as maps in Golang are not concurrency-safe.
1fatal error: concurrent map writes 2 3goroutine 11 [running]: 4github.com/zeromicro/go-zero/core/search.add(0xc00008ed20, {0xc000156d09, 0x16}, {0x1268c00, 0xc0003845a0}) 5 C:/Users/hanleng/go/pkg/mod/github.com/zeromicro/[email protected]/core/search/tree.go:182 +0x2b5 6github.
... Background When passing data through gRPC, switching topics often results in the error: rpc error: code = Internal desc = grpc: error while marshaling: marshaling SubscribeIoStateResponse: size mismatch (see https://github.com/golang/protobuf/issues/1609): calculated=6, measured=8. Following the issue, the most likely cause is that Protobuf messages or sub-messages are shared and concurrently modified. Protobuf does not allow modifications to messages during the encoding process.
Root Cause Analysis The minimal reproducible code is as follows:
...
Concept Graceful Shutdown refers to the orderly termination of a program or service, ensuring that all resources are properly closed, ongoing tasks are completed, and data consistency and integrity are maintained. Unlike a forced exit (such as killing a process directly), a graceful shutdown prevents data loss, resource leaks, or inconsistent system states.
Steps Receive Exit Signals:
The program needs to listen for system signals (e.g., SIGINT, SIGTERM) or custom exit requests to trigger the graceful shutdown process.
...
The concept of syntactic sugar was introduced by British computer scientist Peter Landin, referring to certain types of syntax in programming languages that do not affect functionality but are convenient to use. Syntactic sugar, also known as sugared syntax, does not alter the functionality, and the compiled result is the same as without using syntactic sugar.
1. Short Variable Declaration := Multiple variable assignments may redeclare variables (This does not introduce new variables but only changes the values of existing variables.
...