/**
     * Time in milliseconds that connectors will wait for another HTTP request before
     * closing the connection. When not set, the connector's container-specific default
     * will be used. Use a value of -1 to indicate no (i.e. infinite) timeout.
     */
    private Integer connectionTimeout;

I don't know if this is a bug or a feature. However, I definitely feel that this is not reasonable, in tomcat, the default connectionTimeout value is 2000. In spring boot, however, he does not have a default value, causing the system to have a large number of TIME_WAIT. I think a default value should also be given when it is automatically transferred. Not Null or 0.

Comment From: wilkinsona

As described in the comment you have quoted, when server.connection-timeout has not been set, the embedded container is left to use its default timeout for the connector. If you are seeing different behaviour plesse provide a complete sample that reproduces the problem. At this point we don’t even know what version of Boot you are using.

Comment From: hellojukay

@wilkinsona my spring boot version is 1.5.9.RELEASE

Comment From: wilkinsona

Unfortunately, that’s only part of what we need to know. As I said above, if you are seeing different behaviour plesse provide a complete sample that reproduces the problem.

Comment From: hellojukay

@wilkinsona Hello, to reproduces problem is very simple, as long as you create a spring boot program, use the default tomcat configuration, deployment, will your project and then use nginx to agent for this project, of course, want to open the keepalive nginx, ab command is then used to stress test your project, you will find that the spring boot built-in emerged in tomcat time_wait.

Comment From: wilkinsona

A socket being in TIME_WAIT indicates that the socket has been closed and that the TCP stack is waiting for any additional packets. I'm going to close this issue as I don't think there's a problem with Spring Boot. Specifically, I haven't seen anything that suggests that Tomcat's connections are being configured with an indefinite timeout.

Comment From: hellojukay

when the client send header keepalive, spring boot tomcat should not close the socket in 20 seconds, 20 seconds is a default value in tomcat . but spring boot tomcat not include the default value. the value is 6 seconds?

Comment From: wilkinsona

Tomcat's default is 60 seconds. Spring Boot will leave Tomcat to use that default unless you have configured it. I've just verified this behaviour using one of our samples.

If you want someone to spend some more time looking at this, then you'll need to provide a small sample that shows Spring Boot configuring Tomcat with a timeout other than its default.

Comment From: hellojukay

tomcat conf/server.xml, the default timeout is 20000

    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Comment From: hellojukay

This is my sample

https://github.com/hellojukay/springboot-sample

this is my nginx conf, enable nginx keepalive


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  120s 120s;
    keepalive_requests 10000;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

#        location / {
#           root   html;
#          index  index.html index.htm;
#     }
       root /Users/jukay;
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location /hello {
          proxy_pass http://127.0.0.1:7777;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include servers/*;
}

this is my case, the 7777 port release connection too fast, i think the connect status should not bee TIME_WAIT,It meant that tomcat quickly turned off the connection without waiting for a default timeout. look at this gif,

Comment From: wilkinsona

This has nothing to do with Spring Boot. You're using curl and it closes all the connections that it has opened when it exits.

Comment From: hellojukay

@wilkinsona no,no,no

you can use ab -k to request , connection TIME_WAIT too.

Comment From: happier2

@wilkinsona no,no,no

you can use ab -k to request , connection TIME_WAIT too.

By default, nginx will use protocal http/1.0 to connect with your spring boot application, which will cause lots of short connection between nginx and tomcat. Lots of short connection(frequently open tcp and close tcp) will produce lots of TIME_WAIT.