Solution Approach for Using Proxy in Docker Build

Problem Description When using docker build to package an image, there is a need to access the network via a proxy. The following Dockerfile simulates this scenario: FROM golang:1.12 RUN curl www.google.com --max-time 3 In a typical network environment in China, curl www.google.com cannot return normally. The --max-time option is added to ensure the curl command does not take too long. Configuring the http_proxy Variable First, you need to set the http_proxy and https_proxy environment variables so that network access commands (represented here by curl) can access www.google.com through the proxy server configured in the environment variables. ...

April 18, 2019 · 3 min · Zhiya

Understanding the Behavior of the count Function in PostgreSQL

The use of the count function has always been a topic of debate, especially in MySQL. As PostgreSQL gains popularity, does it have similar issues? Let’s explore the behavior of the count function in PostgreSQL through practical experiments. Building a Test Database Create a test database and a test table. The test table includes three fields: an auto-increment ID, a creation time, and content. The auto-increment ID field is the primary key. ...

April 16, 2019 · 7 min · Zhiya

JWT Pitfalls Guide: Solving the nbf Verification Failure Issue

Phenomenon A freshly issued JWT becomes invalid when used in the next request, resulting in a 422 error. { "msg": "The token is not yet valid (nbf)" } If you wait a few seconds before making the request again (for example, using Chrome Developer Tools’ Replay XHR), it succeeds. Principle of the nbf Field Looking at the error message above, you will notice an nbf, which is a field in the JWT protocol. It stands for Not Before, indicating that the JWT Token is invalid before this time, and is generally set to the issuance time. This raises a hypothesis: in a multi-server environment, if the servers’ times are not synchronized, a token issued by one server might fail verification on another server due to the nbf field. The JWT protocol has already considered such issues, and it specifically mentions using a small leeway to address this in the nbf section. ...

March 26, 2019 · 4 min · Zhiya

Solution Approach for Uploading Large Files Error in nginx + ingress + gunicorn Environment

In a Python Web application deployed on Kubernetes and running with Gunicorn, a series of errors occurred when uploading large files. Here, I document the solution approach. File Upload Process File upload flow: The uploaded file first reaches the host machine where Kubernetes is running. Nginx on the host machine forwards it via Proxy to the Ingress Controller in the Kubernetes cluster, which is also implemented using Nginx. Nginx in the Ingress Controller forwards it via Proxy to Gunicorn. Gunicorn starts several Workers to handle requests, so it forwards the request to a Worker. The Worker is the final Python Web App. Solving Error 413 The first encountered error was 413 Request Entity Too Large. During the upload process, the connection was interrupted (almost always at the same upload percentage), and the request returned 413. Initially, I considered the possibility of Nginx having a request body size limit. Checking the Nginx documentation, I found that the client_max_body_size parameter controls the request body size, with a default setting of 1mb. ...

February 28, 2019 · 4 min · Zhiya

Understanding and Practical Experience with Python's Logging Library

This article starts with the basic concepts of the Python logging library to understand its execution flow and some details that might be overlooked. Log Levels The logging library has 5 preset error levels, plus a NOTSET level, which is the default value for a logger. CRITICAL = 50 ERROR = 40 WARNING = 30 INFO = 20 DEBUG = 10 NOTSET = 0 The logging library also supports custom error levels. As seen in the source code above, there are 10 numeric positions reserved between different error levels, allowing us to add more detailed error levels on top of the preset ones. ...

January 25, 2019 · 7 min · Zhiya