Skip to content

Commit

Permalink
Add connect/idle/requestRead timeout properties for admin HTTP server
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChenX committed Jun 7, 2024
1 parent 2cb342a commit a302378
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package im.turms.server.common.access.admin.web;

import java.time.Duration;

import reactor.netty.http.server.HttpServer;

import im.turms.server.common.access.common.LoopResourcesFactory;
Expand All @@ -26,6 +28,7 @@
import im.turms.server.common.infra.property.env.common.adminapi.AdminHttpProperties;
import im.turms.server.common.infra.thread.ThreadNameConst;

import static io.netty.channel.ChannelOption.CONNECT_TIMEOUT_MILLIS;
import static io.netty.channel.ChannelOption.SO_LINGER;
import static io.netty.channel.ChannelOption.SO_REUSEADDR;
import static io.netty.channel.ChannelOption.TCP_NODELAY;
Expand Down Expand Up @@ -53,7 +56,19 @@ public static HttpServer createHttpServer(AdminHttpProperties httpProperties) {
.childOption(TCP_NODELAY, true)
.runOn(LoopResourcesFactory.createForServer(ThreadNameConst.ADMIN_HTTP_PREFIX))
.metrics(true, () -> new TurmsMicrometerChannelMetricsRecorder(ADMIN_API, "http"));
int connectTimeoutMillis = httpProperties.getConnectTimeoutMillis();
int idleTimeoutMillis = httpProperties.getIdleTimeoutMillis();
int requestReadTimeoutMillis = httpProperties.getRequestReadTimeoutMillis();
if (connectTimeoutMillis > 0) {
http = http.option(CONNECT_TIMEOUT_MILLIS, httpProperties.getConnectTimeoutMillis());
}
if (idleTimeoutMillis > 0) {
http = http.idleTimeout(Duration.ofMillis(idleTimeoutMillis));
}
if (requestReadTimeoutMillis > 0) {
http = http.requestTimeout(Duration.ofMillis(requestReadTimeoutMillis));
}
return SslUtil.apply(http, ssl, false);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package im.turms.server.common.infra.property.env.common.adminapi;

import jakarta.validation.constraints.Min;

import lombok.Data;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import im.turms.server.common.infra.property.env.common.SslProperties;
import im.turms.server.common.infra.property.metadata.Description;

import static im.turms.server.common.infra.unit.ByteSizeUnit.MB;

Expand All @@ -30,10 +33,27 @@
@Data
public class AdminHttpProperties {

@Description("The bind host")
private String host = "0.0.0.0";

@Description("The bind port")
private int port = -1;

@Description("The connect timeout")
@Min(0)
private int connectTimeoutMillis = 30 * 1000;

@Description("The idle timeout on the connection when it is waiting for an HTTP request to come. "
+ "Once the timeout is reached, the connection will be closed")
@Min(0)
private int idleTimeoutMillis = 3 * 60 * 1000;

@Description("The read timeout on the connection when it is waiting for an HTTP request to be fully read. "
+ "Once the timeout is reached, the connection will be closed")
@Min(0)
private int requestReadTimeoutMillis = 3 * 60 * 1000;

@Description("The max request body size in bytes")
private int maxRequestBodySizeBytes = 10 * MB;

@NestedConfigurationProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,36 @@
"value": true
},
"http": {
"connectTimeoutMillis": {
"deprecated": false,
"description": "The connect timeout",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 30000
},
"host": {
"deprecated": false,
"description": "The bind host",
"global": false,
"mutable": false,
"sensitive": false,
"type": "string",
"value": "0.0.0.0"
},
"idleTimeoutMillis": {
"deprecated": false,
"description": "The idle timeout on the connection when it is waiting for an HTTP request to come. Once the timeout is reached, the connection will be closed",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 180000
},
"maxRequestBodySizeBytes": {
"deprecated": false,
"description": "The max request body size in bytes",
"global": false,
"mutable": false,
"sensitive": false,
Expand All @@ -64,11 +84,21 @@
},
"port": {
"deprecated": false,
"description": "The bind port",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 5510
},
"requestReadTimeoutMillis": {
"deprecated": false,
"description": "The read timeout on the connection when it is waiting for an HTTP request to be fully read. Once the timeout is reached, the connection will be closed",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 180000
}
},
"log": {
Expand Down Expand Up @@ -430,16 +460,36 @@
"value": true
},
"http": {
"connectTimeoutMillis": {
"deprecated": false,
"description": "The connect timeout",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 30000
},
"host": {
"deprecated": false,
"description": "The bind host",
"global": false,
"mutable": false,
"sensitive": false,
"type": "string",
"value": "0.0.0.0"
},
"idleTimeoutMillis": {
"deprecated": false,
"description": "The idle timeout on the connection when it is waiting for an HTTP request to come. Once the timeout is reached, the connection will be closed",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 180000
},
"maxRequestBodySizeBytes": {
"deprecated": false,
"description": "The max request body size in bytes",
"global": false,
"mutable": false,
"sensitive": false,
Expand All @@ -448,11 +498,21 @@
},
"port": {
"deprecated": false,
"description": "The bind port",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 9510
},
"requestReadTimeoutMillis": {
"deprecated": false,
"description": "The read timeout on the connection when it is waiting for an HTTP request to be fully read. Once the timeout is reached, the connection will be closed",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 180000
}
},
"log": {
Expand Down Expand Up @@ -2790,16 +2850,36 @@
"value": true
},
"http": {
"connectTimeoutMillis": {
"deprecated": false,
"description": "The connect timeout",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 30000
},
"host": {
"deprecated": false,
"description": "The bind host",
"global": false,
"mutable": false,
"sensitive": false,
"type": "string",
"value": "0.0.0.0"
},
"idleTimeoutMillis": {
"deprecated": false,
"description": "The idle timeout on the connection when it is waiting for an HTTP request to come. Once the timeout is reached, the connection will be closed",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 180000
},
"maxRequestBodySizeBytes": {
"deprecated": false,
"description": "The max request body size in bytes",
"global": false,
"mutable": false,
"sensitive": false,
Expand All @@ -2808,11 +2888,21 @@
},
"port": {
"deprecated": false,
"description": "The bind port",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 8510
},
"requestReadTimeoutMillis": {
"deprecated": false,
"description": "The read timeout on the connection when it is waiting for an HTTP request to be fully read. Once the timeout is reached, the connection will be closed",
"global": false,
"mutable": false,
"sensitive": false,
"type": "int",
"value": 180000
}
},
"log": {
Expand Down
Loading

0 comments on commit a302378

Please sign in to comment.