diff --git a/docs/index.md b/docs/index.md index ecba9aa3..9893e973 100644 --- a/docs/index.md +++ b/docs/index.md @@ -177,6 +177,7 @@ Name | Type | Description ---- | ---- | ----------- authorization | string | *Optional* Username and password for HTTP basic authentication to the rippled server in the format **username:password**. certificate | string | *Optional* A string containing the certificate key of the client in PEM format. (Can be an array of certificates). +connectionTimeout | integer | *Optional* Connection timeout, in milliseconds, before considering connect() to have failed. feeCushion | number | *Optional* Factor to multiply estimated fee by to provide a cushion in case the required fee rises during submission of a transaction. Defaults to `1.2`. key | string | *Optional* A string containing the private key of the client in PEM format. (Can be an array of keys). maxFeeXRP | string | *Optional* Maximum fee to use with transactions, in XRP. Must be a string-encoded number. Defaults to `'2'`. @@ -184,7 +185,7 @@ passphrase | string | *Optional* The passphrase for the private key of the clien proxy | uri string | *Optional* URI for HTTP/HTTPS proxy to use to connect to the rippled server. proxyAuthorization | string | *Optional* Username and password for HTTP basic authentication to the proxy in the format **username:password**. server | uri string | *Optional* URI for rippled websocket port to connect to. Must start with `wss://`, `ws://`, `wss+unix://`, or `ws+unix://`. -timeout | integer | *Optional* Timeout in milliseconds before considering a request to have failed. +timeout | integer | *Optional* Request timeout in milliseconds before considering a request to have failed. See also: connectionTimeout. trace | boolean | *Optional* If true, log rippled requests and responses to stdout. trustedCertificates | array\ | *Optional* Array of PEM-formatted SSL certificates to trust when connecting to a proxy. This is useful if you want to use a self-signed certificate on the proxy server. Note: Each element must contain a single certificate; concatenated certificates are not valid. diff --git a/src/common/connection.ts b/src/common/connection.ts index b948e1d6..95372b77 100644 --- a/src/common/connection.ts +++ b/src/common/connection.ts @@ -27,7 +27,7 @@ export interface ConnectionOptions { key?: string passphrase?: string certificate?: string - timeout: number + timeout: number // request timeout connectionTimeout: number } @@ -119,7 +119,7 @@ function createWebSocket(url: string, config: ConnectionOptions): WebSocket { * ws.send(), but promisified. */ function websocketSendAsync(ws: WebSocket, message: string) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { ws.send(message, undefined, (error) => { if (error) { reject(new DisconnectedError(error.message, error)) @@ -326,7 +326,7 @@ export class Connection extends EventEmitter { this._url = url this._config = { timeout: 20 * 1000, - connectionTimeout: 2 * 1000, + connectionTimeout: 5 * 1000, ...options } if (typeof options.trace === 'function') { @@ -488,7 +488,8 @@ export class Connection extends EventEmitter { this._onConnectionFailed( new ConnectionError( `Error: connect() timed out after ${this._config.connectionTimeout} ms. ` + - `If your internet connection is working, the rippled server may be blocked or inaccessible.` + `If your internet connection is working, the rippled server may be blocked or inaccessible. ` + + `You can also try setting the 'connectionTimeout' option in the RippleAPI constructor.` ) ) }, this._config.connectionTimeout) diff --git a/src/common/schemas/input/api-options.json b/src/common/schemas/input/api-options.json index d8b618de..1da93bef 100644 --- a/src/common/schemas/input/api-options.json +++ b/src/common/schemas/input/api-options.json @@ -28,7 +28,12 @@ }, "timeout": { "type": "integer", - "description": "Timeout in milliseconds before considering a request to have failed.", + "description": "Request timeout in milliseconds before considering a request to have failed. See also: connectionTimeout.", + "minimum": 1 + }, + "connectionTimeout": { + "type": "integer", + "description": "Connection timeout, in milliseconds, before considering connect() to have failed.", "minimum": 1 }, "proxyAuthorization": {