diff --git a/node/src/index.ts b/node/src/index.ts index 097f54f6..5e65f4d6 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -62,6 +62,8 @@ export { const defaultAwsRegion = "us-west-2"; +const defaultRequestTimeout = 10_000 + export interface AwsCredentials { accessKeyId: string @@ -119,6 +121,11 @@ export interface ConnectionOptions { */ hostOverride?: string + /** + * Duration in milliseconds for request timeout. Default = 10,000 (10 seconds) + */ + timeout?: number + /** * (For LanceDB OSS only): The interval, in seconds, at which to check for * updates to the table from other processes. If None, then consistency is not @@ -204,7 +211,8 @@ export async function connect( awsCredentials: undefined, awsRegion: defaultAwsRegion, apiKey: undefined, - region: defaultAwsRegion + region: defaultAwsRegion, + timeout: defaultRequestTimeout }, arg ); diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 9992abbb..78b1edfc 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -41,7 +41,7 @@ async function callWithMiddlewares ( if (i > middlewares.length) { const headers = Object.fromEntries(req.headers.entries()) const params = Object.fromEntries(req.params?.entries() ?? []) - const timeout = 10000 + const timeout = opts?.timeout let res if (req.method === Method.POST) { res = await axios.post( @@ -82,6 +82,7 @@ async function callWithMiddlewares ( interface MiddlewareInvocationOptions { responseType?: ResponseType + timeout?: number, } /** @@ -123,15 +124,19 @@ export class HttpLancedbClient { private readonly _url: string private readonly _apiKey: () => string private readonly _middlewares: HttpLancedbClientMiddleware[] + private readonly _timeout: number | undefined public constructor ( url: string, apiKey: string, - private readonly _dbName?: string + timeout?: number, + private readonly _dbName?: string, + ) { this._url = url this._apiKey = () => apiKey this._middlewares = [] + this._timeout = timeout } get uri (): string { @@ -230,7 +235,10 @@ export class HttpLancedbClient { let response try { - response = await callWithMiddlewares(req, this._middlewares, { responseType }) + response = await callWithMiddlewares(req, this._middlewares, { + responseType, + timeout: this._timeout, + }) // return response } catch (err: any) { @@ -267,7 +275,7 @@ export class HttpLancedbClient { * Make a clone of this client */ private clone (): HttpLancedbClient { - const clone = new HttpLancedbClient(this._url, this._apiKey(), this._dbName) + const clone = new HttpLancedbClient(this._url, this._apiKey(), this._timeout, this._dbName) for (const mw of this._middlewares) { clone._middlewares.push(mw) } diff --git a/node/src/remote/index.ts b/node/src/remote/index.ts index 9dcd44ee..11e20a2f 100644 --- a/node/src/remote/index.ts +++ b/node/src/remote/index.ts @@ -72,6 +72,7 @@ export class RemoteConnection implements Connection { this._client = new HttpLancedbClient( server, opts.apiKey, + opts.timeout, opts.hostOverride === undefined ? undefined : this._dbName ) }