A proper timeout prevents your program from blocking indefinitely on unresponsive requests while still allowing enough time for tasks to complete. The V2.0 Node.js SDK supports timeout configuration at both the per-request and global levels.
Configuration methods
Note
The priority of timeout settings from highest to lowest is as follows: RuntimeOptions settings, Config settings, and default configurations.
-
Use the default timeout settings. The default connection timeout is 5,000 milliseconds, and the default read timeout is 10,000 milliseconds.
-
Configure RuntimeOptions.
const { RuntimeOptions } = require('@alicloud/tea-util'); // Create a RuntimeOptions instance and set runtime parameters. const runtime = new RuntimeOptions({ // Set the connection timeout. connectTimeout: 10000, // Set the read timeout. readTimeout: 10000, });import * as $Util from '@alicloud/tea-util'; // Create a RuntimeOptions instance and set runtime parameters. const runtime = new $Util.RuntimeOptions({ // Set the connection timeout. connectTimeout: 10000, // Set the read timeout. readTimeout: 10000, }); -
Configure a global timeout by using Config.
const { Config } = require('@alicloud/openapi-client'); const config = new Config({ // Set the connection timeout. connectTimeout: 10000, // Set the read timeout. readTimeout: 10000, });import * as $OpenApi from '@alicloud/openapi-client'; const config = new $OpenApi.Config({ // Set the connection timeout. connectTimeout: 10000, // Set the read timeout. readTimeout: 10000, });