You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The current Stop() method of go-zero's HTTP service (rest.Server) only closes the logging module and lacks an elegant shutdown mechanism. This causes port occupation conflicts when running multiple test cases consecutively (e.g., address already in use), as the port is not released properly after tests.
Describe the solution you'd like
Implement the following logic in rest.Server.Stop():
Stop accepting new requests (close the listening port).
Wait for all active requests to complete or timeout.
Release the port and other resources.
Provide a configurable timeout period to avoid infinite waiting.
Reference the implementation of Go's native http.Server.Shutdown().
or signal-triggered graceful shutdown (e.g., SIGTERM)
Describe alternatives you've considered
Manually invoking net/http's graceful shutdown in test code, but this requires intrusive modifications.
Using third-party libraries (e.g., github.com/facebookgo/grace), which adds dependency complexity.
Force-killing processes (e.g., kill -9), but this interrupts active requests.
Additional context
Example of test failure due to port occupation:
func TestServer1(t *testing.T) {
server := rest.MustNewServer(rest.RestConf{Port: 8080})
defer server.Stop() // Current Stop() is ineffective; port remains occupied
// Test logic...
}
func TestServer2(t *testing.T) {
server := rest.MustNewServer(rest.RestConf{Port: 8080}) // Error: port already in use
// Test logic...
}
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
The current Stop() method of go-zero's HTTP service (rest.Server) only closes the logging module and lacks an elegant shutdown mechanism. This causes port occupation conflicts when running multiple test cases consecutively (e.g., address already in use), as the port is not released properly after tests.
Describe the solution you'd like
Implement the following logic in rest.Server.Stop():
or signal-triggered graceful shutdown (e.g., SIGTERM)
Describe alternatives you've considered
Additional context
Example of test failure due to port occupation:
The text was updated successfully, but these errors were encountered: