Skip to content

Commit f027fad

Browse files
author
Peter Schretlen
authored
revert configurable global socket timeouts (#31603) (#41837)
1 parent 29fa09b commit f027fad

File tree

13 files changed

+13
-127
lines changed

13 files changed

+13
-127
lines changed

docs/setup/settings.asciidoc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ Specify the position of the subdomain the URL with the token `{s}`.
209209

210210
`server.host:`:: *Default: "localhost"* This setting specifies the host of the back end server.
211211

212-
`server.keepaliveTimeout:`:: *Default: "120000"* The number of milliseconds to wait for additional data before restarting
213-
the `server.socketTimeout` counter.
214-
215212
`server.maxPayloadBytes:`:: *Default: 1048576* The maximum payload size in bytes for incoming server requests.
216213

217214
`server.name:`:: *Default: "your-hostname"* A human-readable display name that identifies this Kibana instance.
@@ -220,9 +217,6 @@ the `server.socketTimeout` counter.
220217

221218
`server.ssl.enabled:`:: *Default: "false"* Enables SSL for outgoing requests from the Kibana server to the browser. When set to `true`, `server.ssl.certificate` and `server.ssl.key` are required
222219

223-
`server.socketTimeout:`:: *Default: "120000"* The number of milliseconds to wait before closing an
224-
inactive socket.
225-
226220
`server.ssl.cert:`:: Path to the PEM-format SSL certificate. This file enables
227221
SSL for outgoing requests from the Kibana server to the browser.
228222
deprecated[5.3.0,Replaced by `server.ssl.certificate`]

src/core/server/http/__snapshots__/http_config.test.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ Object {
1414
"autoListen": true,
1515
"cors": false,
1616
"host": "localhost",
17-
"keepaliveTimeout": 120000,
1817
"maxPayload": ByteSizeValue {
1918
"valueInBytes": 1048576,
2019
},
2120
"port": 5601,
2221
"rewriteBasePath": false,
23-
"socketTimeout": 120000,
2422
"ssl": Object {
2523
"cipherSuites": Array [
2624
"ECDHE-RSA-AES128-GCM-SHA256",

src/core/server/http/base_path_proxy_server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { sample } from 'lodash';
2424
import { DevConfig } from '../dev';
2525
import { Logger } from '../logging';
2626
import { HttpConfig } from './http_config';
27-
import { createServer, getListenerOptions, getServerOptions } from './http_tools';
27+
import { createServer, getServerOptions } from './http_tools';
2828

2929
const alphabet = 'abcdefghijklmnopqrztuvwxyz'.split('');
3030

@@ -62,8 +62,7 @@ export class BasePathProxyServer {
6262
this.log.debug('starting basepath proxy server');
6363

6464
const serverOptions = getServerOptions(this.httpConfig);
65-
const listenerOptions = getListenerOptions(this.httpConfig);
66-
this.server = createServer(serverOptions, listenerOptions);
65+
this.server = createServer(serverOptions);
6766

6867
// Register hapi plugin that adds proxying functionality. It can be configured
6968
// through the route configuration object (see { handler: { proxy: ... } }).

src/core/server/http/http_config.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,6 @@ describe('with TLS', () => {
127127
expect(config.ssl.certificateAuthorities).toBe('/authority/');
128128
});
129129

130-
test('can specify socket timeouts', () => {
131-
const obj = {
132-
keepaliveTimeout: 1e5,
133-
socketTimeout: 5e5,
134-
};
135-
const { keepaliveTimeout, socketTimeout } = HttpConfig.schema.validate(obj);
136-
expect(keepaliveTimeout).toBe(1e5);
137-
expect(socketTimeout).toBe(5e5);
138-
});
139-
140130
test('can specify several `certificateAuthorities`', () => {
141131
const httpSchema = HttpConfig.schema;
142132
const obj = {

src/core/server/http/http_config.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ const createHttpSchema = schema.object(
6161
}),
6262
rewriteBasePath: schema.boolean({ defaultValue: false }),
6363
ssl: SslConfig.schema,
64-
keepaliveTimeout: schema.number({
65-
defaultValue: 120000,
66-
}),
67-
socketTimeout: schema.number({
68-
defaultValue: 120000,
69-
}),
7064
},
7165
{
7266
validate: config => {
@@ -99,8 +93,6 @@ export class HttpConfig {
9993

10094
public autoListen: boolean;
10195
public host: string;
102-
public keepaliveTimeout: number;
103-
public socketTimeout: number;
10496
public port: number;
10597
public cors: boolean | { origin: string[] };
10698
public maxPayload: ByteSizeValue;
@@ -121,8 +113,6 @@ export class HttpConfig {
121113
this.basePath = config.basePath;
122114
this.rewriteBasePath = config.rewriteBasePath;
123115
this.publicDir = env.staticFilesDir;
124-
this.keepaliveTimeout = config.keepaliveTimeout;
125-
this.socketTimeout = config.socketTimeout;
126116
this.ssl = new SslConfig(config.ssl);
127117
}
128118
}

src/core/server/http/http_server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Server, ServerOptions } from 'hapi';
2222
import { modifyUrl } from '../../utils';
2323
import { Logger } from '../logging';
2424
import { HttpConfig } from './http_config';
25-
import { createServer, getListenerOptions, getServerOptions } from './http_tools';
25+
import { createServer, getServerOptions } from './http_tools';
2626
import { Router } from './router';
2727

2828
export interface HttpServerInfo {
@@ -52,8 +52,7 @@ export class HttpServer {
5252
this.log.debug('starting http server');
5353

5454
const serverOptions = getServerOptions(config);
55-
const listenerOptions = getListenerOptions(config);
56-
this.server = createServer(serverOptions, listenerOptions);
55+
this.server = createServer(serverOptions);
5756

5857
this.setupBasePathRewrite(this.server, config);
5958

src/core/server/http/http_tools.test.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@
1919

2020
import { Request, ResponseToolkit } from 'hapi';
2121
import Joi from 'joi';
22-
import supertest from 'supertest';
23-
24-
import { logger } from '../logging/__mocks__';
25-
26-
import { ByteSizeValue } from '@kbn/config-schema';
27-
import { HttpConfig } from './http_config';
28-
import { HttpServer } from './http_server';
2922
import { defaultValidationErrorHandler, HapiValidationError } from './http_tools';
30-
import { Router } from './router';
3123

3224
const emptyOutput = {
3325
statusCode: 400,
@@ -65,37 +57,3 @@ describe('defaultValidationErrorHandler', () => {
6557
}
6658
});
6759
});
68-
69-
describe('timeouts', () => {
70-
const server = new HttpServer(logger.get());
71-
72-
test('returns 408 on timeout error', async () => {
73-
const router = new Router('');
74-
router.get({ path: '/a', validate: false }, async (req, res) => {
75-
await new Promise(resolve => setTimeout(resolve, 2000));
76-
return res.ok({});
77-
});
78-
router.get({ path: '/b', validate: false }, async (req, res) => res.ok({}));
79-
server.registerRouter(router);
80-
81-
const config = {
82-
socketTimeout: 1000,
83-
host: '127.0.0.1',
84-
maxPayload: new ByteSizeValue(1024),
85-
ssl: {},
86-
} as HttpConfig;
87-
88-
const { server: innerServer } = await server.start(config);
89-
await supertest(innerServer.listener)
90-
.get('/a')
91-
.expect(408);
92-
await supertest(innerServer.listener)
93-
.get('/b')
94-
.expect(200);
95-
});
96-
97-
afterAll(async () => {
98-
await server.stop();
99-
logger.mockClear();
100-
});
101-
});

src/core/server/http/http_tools.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,11 @@ export function getServerOptions(config: HttpConfig, { configureTLS = true } = {
7878
return options;
7979
}
8080

81-
export function getListenerOptions(config: HttpConfig) {
82-
return {
83-
keepaliveTimeout: config.keepaliveTimeout,
84-
socketTimeout: config.socketTimeout,
85-
};
86-
}
87-
88-
interface ListenerOptions {
89-
keepaliveTimeout: number;
90-
socketTimeout: number;
91-
}
92-
93-
export function createServer(serverOptions: ServerOptions, listenerOptions: ListenerOptions) {
94-
const server = new Server(serverOptions);
81+
export function createServer(options: ServerOptions) {
82+
const server = new Server(options);
9583

96-
server.listener.keepAliveTimeout = listenerOptions.keepaliveTimeout;
97-
server.listener.setTimeout(listenerOptions.socketTimeout);
98-
server.listener.on('timeout', socket => {
99-
if (socket.writable) {
100-
socket.end(Buffer.from('HTTP/1.1 408 Request Timeout\r\n\r\n', 'ascii'));
101-
} else {
102-
socket.destroy();
103-
}
104-
});
84+
// Revert to previous 120 seconds keep-alive timeout in Node < 8.
85+
server.listener.keepAliveTimeout = 120e3;
10586
server.listener.on('clientError', (err, socket) => {
10687
if (socket.writable) {
10788
socket.end(Buffer.from('HTTP/1.1 400 Bad Request\r\n\r\n', 'ascii'));

src/core/server/http/https_redirect_server.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { format as formatUrl } from 'url';
2222

2323
import { Logger } from '../logging';
2424
import { HttpConfig } from './http_config';
25-
import { createServer, getListenerOptions, getServerOptions } from './http_tools';
25+
import { createServer, getServerOptions } from './http_tools';
2626

2727
export class HttpsRedirectServer {
2828
private server?: Server;
@@ -42,13 +42,10 @@ export class HttpsRedirectServer {
4242
// Redirect server is configured in the same way as any other HTTP server
4343
// within the platform with the only exception that it should always be a
4444
// plain HTTP server, so we just ignore `tls` part of options.
45-
this.server = createServer(
46-
{
47-
...getServerOptions(config, { configureTLS: false }),
48-
port: config.ssl.redirectHttpFromPort,
49-
},
50-
getListenerOptions(config)
51-
);
45+
this.server = createServer({
46+
...getServerOptions(config, { configureTLS: false }),
47+
port: config.ssl.redirectHttpFromPort,
48+
});
5249

5350
this.server.ext('onRequest', (request: Request, responseToolkit: ResponseToolkit) => {
5451
return responseToolkit

src/core/server/legacy_compat/config/__snapshots__/legacy_object_to_config_adapter.test.ts.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ Object {
66
"basePath": "/abc",
77
"cors": false,
88
"host": "host",
9-
"keepaliveTimeout": 5000,
109
"maxPayload": 1000,
1110
"port": 1234,
1211
"rewriteBasePath": false,
13-
"socketTimeout": 2000,
1412
"ssl": Object {
1513
"enabled": true,
1614
"keyPassphrase": "some-phrase",
@@ -25,11 +23,9 @@ Object {
2523
"basePath": "/abc",
2624
"cors": false,
2725
"host": "host",
28-
"keepaliveTimeout": 5000,
2926
"maxPayload": 1000,
3027
"port": 1234,
3128
"rewriteBasePath": false,
32-
"socketTimeout": 2000,
3329
"ssl": Object {
3430
"certificate": "cert",
3531
"enabled": true,
@@ -44,11 +40,9 @@ Object {
4440
"basePath": "/abc",
4541
"cors": false,
4642
"host": "host",
47-
"keepaliveTimeout": 5000,
4843
"maxPayload": 1000,
4944
"port": 1234,
5045
"rewriteBasePath": false,
51-
"socketTimeout": 2000,
5246
"ssl": Object {
5347
"certificate": "deprecated-cert",
5448
"enabled": true,
@@ -63,11 +57,9 @@ Object {
6357
"basePath": "/abc",
6458
"cors": false,
6559
"host": "host",
66-
"keepaliveTimeout": 5000,
6760
"maxPayload": 1000,
6861
"port": 1234,
6962
"rewriteBasePath": false,
70-
"socketTimeout": 2000,
7163
"ssl": Object {
7264
"certificate": "cert",
7365
"enabled": false,

0 commit comments

Comments
 (0)