'why nginx close upstream keepalive connection when user cancel request

in my case, i use keepalive params to keepalive the upstream. and i use nginx for grpc balancing.

upstream grpc_servers {
server  ${GRPC_PROXY};
keepalive_timeout 65s;
keepalive 1000;
keepalive_requests 1000;
}

the http section is

http {
    proxy_connect_timeout  30s;
    proxy_send_timeout  30s;
    proxy_read_timeout  30s;
    client_header_timeout 15s;
    client_body_timeout 15s;
    keepalive_timeout  120s 120s;
    keepalive_requests 1000;
    send_timeout 15s;
    proxy_ignore_client_abort on;
    include '/etc/nginx/conf.d/backend.conf';
}

but when i test the long time request, the user cancel the request. i found nginx also close the upstream keepalive connection the nginx log is below

2022/03/15 13:14:45 [debug] 1630#1630: *108704 http2 read handler                                                                                                                        
2022/03/15 13:14:45 [debug] 1630#1630: *108704 SSL_read: 0                                                                                                                               
2022/03/15 13:14:45 [debug] 1630#1630: *108704 SSL_get_error: 5                                                                                                                          
2022/03/15 13:14:45 [debug] 1630#1630: *108704 peer shutdown SSL cleanly                                                                                                                 
2022/03/15 13:14:45 [info] 1630#1630: *108704 client prematurely closed connection while processing HTTP/2 connection, client: 172.30.0.7, server: 0.0.0.0:9081                          
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http run request: "/config.Config/DelayTest?"                                                                                             
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http upstream check client, write event:0, "/config.Config/DelayTest"                                                                     
2022/03/15 13:14:45 [debug] 1630#1630: *108704 finalize http upstream request: 499                                                                                                       
2022/03/15 13:14:45 [debug] 1630#1630: *108704 finalize grpc request                                                                                                                     
2022/03/15 13:14:45 [debug] 1630#1630: *108704 free keepalive peer                                                                                                                       
2022/03/15 13:14:45 [debug] 1630#1630: *108704 free rr peer 1 0                                                                                                                          
2022/03/15 13:14:45 [debug] 1630#1630: *108704 close http upstream connection: 13                                                                                                        
2022/03/15 13:14:45 [debug] 1630#1630: *108704 run cleanup: 00007FE60F969D50                                                                                                             
2022/03/15 13:14:45 [debug] 1630#1630: *108704 free: 00007FE60F969D00, unused: 24                                                                                                        
2022/03/15 13:14:45 [debug] 1630#1630: *108704 free: 00007FE60F969640, unused: 64                                                                                                        
2022/03/15 13:14:45 [debug] 1630#1630: *108704 event timer del: 13: 1146016191                                                                                                           
2022/03/15 13:14:45 [debug] 1630#1630: *108704 reusable connection: 0                                                                                                                    
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http finalize request: 499, "/config.Config/DelayTest?" a:1, c:1                                                                          
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http terminate request count:1                                                                                                            
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http terminate cleanup count:1 blk:0                                                                                                      
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http posted request: "/config.Config/DelayTest?"                                                                                          
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http terminate handler count:1                                                                                                            
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http request count:1 blk:0                                                                                                                
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http2 close stream 1, queued 0, processing 1, pushing 0                                                                                   
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http close request                                                                                                                        
2022/03/15 13:14:45 [debug] 1630#1630: *108704 http log handler 

i want to know if is there any way to keepalive the upstream even user close client connection?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source