mirror of
https://github.com/appium/appium.git
synced 2026-02-21 18:59:08 -06:00
feat(appium): Make server graceful shutdown timeout configurable via command line args (#20641)
This commit is contained in:
@@ -19,6 +19,7 @@ export default {
|
||||
port: 4723,
|
||||
relaxedSecurityEnabled: false,
|
||||
sessionOverride: false,
|
||||
shutdownTimeout: 5000,
|
||||
strictCaps: false,
|
||||
useDrivers: [],
|
||||
usePlugins: []
|
||||
|
||||
@@ -31,7 +31,6 @@ import {DEFAULT_BASE_PATH} from '../constants';
|
||||
import {fs, timing} from '@appium/support';
|
||||
|
||||
const KEEP_ALIVE_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
|
||||
const SERVER_CLOSE_TIMEOUT_MS = 5000;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -82,7 +81,7 @@ async function server(opts) {
|
||||
routeConfiguringFunction,
|
||||
port,
|
||||
hostname,
|
||||
cliArgs = {},
|
||||
cliArgs = /** @type {import('@appium/types').ServerArgs} */ ({}),
|
||||
allowCors = true,
|
||||
basePath = DEFAULT_BASE_PATH,
|
||||
extraMethodMap = {},
|
||||
@@ -104,6 +103,7 @@ async function server(opts) {
|
||||
httpServer,
|
||||
reject,
|
||||
keepAliveTimeout,
|
||||
gracefulShutdownTimeout: cliArgs.shutdownTimeout,
|
||||
});
|
||||
configureServer({
|
||||
app,
|
||||
@@ -191,7 +191,7 @@ function configureServer({
|
||||
* @param {ConfigureHttpOpts} opts
|
||||
* @returns {AppiumServer}
|
||||
*/
|
||||
function configureHttp({httpServer, reject, keepAliveTimeout}) {
|
||||
function configureHttp({httpServer, reject, keepAliveTimeout, gracefulShutdownTimeout}) {
|
||||
/**
|
||||
* @type {AppiumServer}
|
||||
*/
|
||||
@@ -214,12 +214,15 @@ function configureHttp({httpServer, reject, keepAliveTimeout}) {
|
||||
log.info('Closing Appium HTTP server');
|
||||
const timer = new timing.Timer().start();
|
||||
const onTimeout = setTimeout(() => {
|
||||
log.info(
|
||||
`Not all active connections have been closed within ` +
|
||||
`${timer.getDuration().asMilliSeconds.toFixed(0)}ms. Exiting anyway.`
|
||||
);
|
||||
if (gracefulShutdownTimeout > 0) {
|
||||
log.info(
|
||||
`Not all active connections have been closed within ${gracefulShutdownTimeout}ms. ` +
|
||||
`This timeout might be customized by the --shutdown-timeout command line ` +
|
||||
`argument. Closing the server anyway.`
|
||||
);
|
||||
}
|
||||
process.exit(process.exitCode ?? 0);
|
||||
}, SERVER_CLOSE_TIMEOUT_MS);
|
||||
}, gracefulShutdownTimeout);
|
||||
httpServer.once('close', () => {
|
||||
log.info(
|
||||
`Appium HTTP server has been succesfully closed after ` +
|
||||
@@ -323,6 +326,9 @@ export {server, configureServer, normalizeBasePath};
|
||||
* @property {import('http').Server} httpServer - HTTP server instance
|
||||
* @property {(error?: any) => void} reject - Rejection function from `Promise` constructor
|
||||
* @property {number} keepAliveTimeout - Keep-alive timeout in milliseconds
|
||||
* @property {number} gracefulShutdownTimeout - For how long the server should delay its
|
||||
* shutdown before force-closing all open connections to it. Providing zero will force-close
|
||||
* the server without waiting for any connections.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -249,12 +249,34 @@ export const AppiumConfigJsonSchema = /** @type {const} */ ({
|
||||
type: 'boolean',
|
||||
appiumCliDest: 'relaxedSecurityEnabled',
|
||||
},
|
||||
'shutdown-timeout': {
|
||||
default: 5000,
|
||||
description: 'For how long the server should delay its shutdown before force-closing all open connections to it. ' +
|
||||
'Setting its value to zero should close the server without waiting for active connections.',
|
||||
title: 'Graceful server shutdown timeout in milliseconds',
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
},
|
||||
'session-override': {
|
||||
default: false,
|
||||
description: 'Enables session override (clobbering)',
|
||||
title: 'session-override config',
|
||||
type: 'boolean',
|
||||
},
|
||||
'ssl-cert-path': {
|
||||
description:
|
||||
'Full path to the .cert file if TLS is used. Must be provided together with "ssl-key-path"',
|
||||
title: '.cert file path',
|
||||
appiumCliDest: 'sslCertificatePath',
|
||||
type: 'string',
|
||||
},
|
||||
'ssl-key-path': {
|
||||
description:
|
||||
'Full path to the .key file if TLS is used. Must be provided together with "ssl-cert-path"',
|
||||
title: '.key file path',
|
||||
appiumCliDest: 'sslKeyPath',
|
||||
type: 'string',
|
||||
},
|
||||
'strict-caps': {
|
||||
default: false,
|
||||
description:
|
||||
@@ -310,20 +332,6 @@ export const AppiumConfigJsonSchema = /** @type {const} */ ({
|
||||
title: 'webhook config',
|
||||
type: 'string',
|
||||
},
|
||||
'ssl-cert-path': {
|
||||
description:
|
||||
'Full path to the .cert file if TLS is used. Must be provided together with "ssl-key-path"',
|
||||
title: '.cert file path',
|
||||
appiumCliDest: 'sslCertificatePath',
|
||||
type: 'string',
|
||||
},
|
||||
'ssl-key-path': {
|
||||
description:
|
||||
'Full path to the .key file if TLS is used. Must be provided together with "ssl-cert-path"',
|
||||
title: '.key file path',
|
||||
appiumCliDest: 'sslKeyPath',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
title: 'server config',
|
||||
type: 'object',
|
||||
|
||||
@@ -251,12 +251,31 @@
|
||||
"type": "boolean",
|
||||
"appiumCliDest": "relaxedSecurityEnabled"
|
||||
},
|
||||
"shutdown-timeout": {
|
||||
"default": 5000,
|
||||
"description": "For how long the server should delay its shutdown before force-closing all open connections to it. Setting its value to zero should close the server without waiting for active connections.",
|
||||
"title": "Graceful server shutdown timeout in milliseconds",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"session-override": {
|
||||
"default": false,
|
||||
"description": "Enables session override (clobbering)",
|
||||
"title": "session-override config",
|
||||
"type": "boolean"
|
||||
},
|
||||
"ssl-cert-path": {
|
||||
"description": "Full path to the .cert file if TLS is used. Must be provided together with \"ssl-key-path\"",
|
||||
"title": ".cert file path",
|
||||
"appiumCliDest": "sslCertificatePath",
|
||||
"type": "string"
|
||||
},
|
||||
"ssl-key-path": {
|
||||
"description": "Full path to the .key file if TLS is used. Must be provided together with \"ssl-cert-path\"",
|
||||
"title": ".key file path",
|
||||
"appiumCliDest": "sslKeyPath",
|
||||
"type": "string"
|
||||
},
|
||||
"strict-caps": {
|
||||
"default": false,
|
||||
"description": "Cause sessions to fail if desired caps are sent in that Appium does not recognize as valid for the selected device",
|
||||
@@ -305,18 +324,6 @@
|
||||
"format": "uri",
|
||||
"title": "webhook config",
|
||||
"type": "string"
|
||||
},
|
||||
"ssl-cert-path": {
|
||||
"description": "Full path to the .cert file if TLS is used. Must be provided together with \"ssl-key-path\"",
|
||||
"title": ".cert file path",
|
||||
"appiumCliDest": "sslCertificatePath",
|
||||
"type": "string"
|
||||
},
|
||||
"ssl-key-path": {
|
||||
"description": "Full path to the .key file if TLS is used. Must be provided together with \"ssl-cert-path\"",
|
||||
"title": ".key file path",
|
||||
"appiumCliDest": "sslKeyPath",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "server config",
|
||||
|
||||
@@ -127,10 +127,22 @@ export type PortConfig = number;
|
||||
* Disable additional security checks, so it is possible to use some advanced features, provided by drivers supporting this option. Only enable it if all the clients are in the trusted network and it's not the case if a client could potentially break out of the session sandbox. Specific features can be overridden by using "deny-insecure"
|
||||
*/
|
||||
export type RelaxedSecurityConfig = boolean;
|
||||
/**
|
||||
* For how long the server should delay its shutdown before force-closing all open connections to it. Setting its value to zero should close the server without waiting for active connections.
|
||||
*/
|
||||
export type GracefulServerShutdownTimeoutInMilliseconds = number;
|
||||
/**
|
||||
* Enables session override (clobbering)
|
||||
*/
|
||||
export type SessionOverrideConfig = boolean;
|
||||
/**
|
||||
* Full path to the .cert file if TLS is used. Must be provided together with "ssl-key-path"
|
||||
*/
|
||||
export type CertFilePath = string;
|
||||
/**
|
||||
* Full path to the .key file if TLS is used. Must be provided together with "ssl-cert-path"
|
||||
*/
|
||||
export type KeyFilePath = string;
|
||||
/**
|
||||
* Cause sessions to fail if desired caps are sent in that Appium does not recognize as valid for the selected device
|
||||
*/
|
||||
@@ -155,14 +167,6 @@ export type UsePluginsConfig = string[];
|
||||
* Also send log output to this http listener
|
||||
*/
|
||||
export type WebhookConfig = string;
|
||||
/**
|
||||
* Full path to the .cert file if TLS is used. Must be provided together with "ssl-key-path"
|
||||
*/
|
||||
export type CertFilePath = string;
|
||||
/**
|
||||
* Full path to the .key file if TLS is used. Must be provided together with "ssl-cert-path"
|
||||
*/
|
||||
export type KeyFilePath = string;
|
||||
|
||||
/**
|
||||
* A schema for Appium configuration files
|
||||
@@ -204,15 +208,16 @@ export interface ServerConfig {
|
||||
plugin?: PluginConfig;
|
||||
port?: PortConfig;
|
||||
"relaxed-security"?: RelaxedSecurityConfig;
|
||||
"shutdown-timeout"?: GracefulServerShutdownTimeoutInMilliseconds;
|
||||
"session-override"?: SessionOverrideConfig;
|
||||
"ssl-cert-path"?: CertFilePath;
|
||||
"ssl-key-path"?: KeyFilePath;
|
||||
"strict-caps"?: StrictCapsConfig;
|
||||
tmp?: TmpConfig;
|
||||
"trace-dir"?: TraceDirConfig;
|
||||
"use-drivers"?: UseDriversConfig;
|
||||
"use-plugins"?: UsePluginsConfig;
|
||||
webhook?: WebhookConfig;
|
||||
"ssl-cert-path"?: CertFilePath;
|
||||
"ssl-key-path"?: KeyFilePath;
|
||||
}
|
||||
/**
|
||||
* Set the default desired capabilities, which will be set on each session unless overridden by received capabilities. If a string, a path to a JSON file containing the capabilities, or raw JSON.
|
||||
|
||||
Reference in New Issue
Block a user