Skip to content

Commit 0b4813d

Browse files
Update files
1 parent 3174be1 commit 0b4813d

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

docs/pages/reference/configuration/environment-variables.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,30 @@ Until v0.35, the default value was `schema`.
10611061
It can be also set using the [`schema_path` configuration
10621062
option](/reference/configuration/config#schema_path).
10631063

1064+
## `CUBEJS_SERVER_HEADERS_TIMEOUT`
1065+
1066+
Limit the amount of time the parser will wait to receive the complete HTTP headers.
1067+
If the timeout expires, the server responds with status 408 without
1068+
forwarding the request to the request listener and then closes the connection.
1069+
1070+
It must be set to a non-zero value (e.g. 120 seconds) to protect against
1071+
potential Denial-of-Service attacks in case the server is deployed without a
1072+
reverse proxy in front.
1073+
1074+
| Possible Values | Default in Development | Default in Production |
1075+
| ----------------------------------------- | ---------------------- | --------------------- |
1076+
| A valid number or string representing one | 60000 | 60000 |
1077+
1078+
1079+
## `CUBEJS_SERVER_KEEP_ALIVE_TIMEOUT`
1080+
1081+
The number of milliseconds of inactivity a server needs to wait for additional incoming data,
1082+
after it has finished writing the last response, before a socket will be destroyed.
1083+
1084+
| Possible Values | Default in Development | Default in Production |
1085+
| ----------------------------------------- | ---------------------- | --------------------- |
1086+
| A valid number or string representing one | 5000 | 5000 |
1087+
10641088
## `CUBEJS_SQL_USER`
10651089

10661090
A username required to access the [SQL API][ref-sql-api].

packages/cubejs-backend-shared/src/env.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ const variables: Record<string, (...args: any) => any> = {
144144
webSockets: () => get('CUBEJS_WEB_SOCKETS')
145145
.default('false')
146146
.asBoolStrict(),
147+
serverHeadersTimeout: () => get('CUBEJS_SERVER_HEADERS_TIMEOUT')
148+
.default('60000')
149+
.asInt(),
150+
serverKeepAliveTimeout: () => get('CUBEJS_SERVER_KEEP_ALIVE_TIMEOUT')
151+
.default('5000')
152+
.asInt(),
147153
rollupOnlyMode: () => get('CUBEJS_ROLLUP_ONLY')
148154
.default('false')
149155
.asBoolStrict(),

packages/cubejs-server/src/server.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ interface HttpOptions {
3434

3535
export interface CreateOptions extends CoreCreateOptions, WebSocketServerOptions, SQLServerOptions {
3636
webSockets?: boolean;
37+
sqlPort?: number;
38+
pgSqlPort?: number;
39+
gatewayPort?: number;
40+
serverKeepAliveTimeout?: number;
41+
serverHeadersTimeout?: number;
3742
http?: HttpOptions;
3843
gracefulShutdown?: number;
3944
}
@@ -47,7 +52,7 @@ type RequireOne<T, K extends keyof T> = {
4752
export class CubejsServer {
4853
protected readonly core: CubeCore;
4954

50-
protected readonly config: RequireOne<CreateOptions, 'webSockets' | 'http' | 'sqlPort' | 'pgSqlPort'>;
55+
protected readonly config: RequireOne<CreateOptions, 'webSockets' | 'http' | 'sqlPort' | 'pgSqlPort' | 'serverKeepAliveTimeout' | 'serverHeadersTimeout'>;
5156

5257
protected server: GracefulHttpServer | null = null;
5358

@@ -64,6 +69,8 @@ export class CubejsServer {
6469
sqlPort: config.sqlPort || getEnv('sqlPort'),
6570
pgSqlPort: config.pgSqlPort || getEnv('pgSqlPort'),
6671
gatewayPort: config.gatewayPort || getEnv('nativeApiGatewayPort'),
72+
serverKeepAliveTimeout: config.serverKeepAliveTimeout || getEnv('serverKeepAliveTimeout'),
73+
serverHeadersTimeout: config.serverHeadersTimeout || getEnv('serverHeadersTimeout'),
6774
http: {
6875
...config.http,
6976
cors: {
@@ -103,6 +110,8 @@ export class CubejsServer {
103110
}
104111

105112
this.server = gracefulHttp(http.createServer(options, app));
113+
this.server.keepAliveTimeout = this.config.serverKeepAliveTimeout;
114+
this.server.headersTimeout = this.config.serverKeepAliveTimeout;
106115

107116
if (this.config.webSockets) {
108117
this.socketServer = new WebSocketServer(this.core, this.config);

0 commit comments

Comments
 (0)