Skip to content

Add new fileScanners.scanTimeout config value #2429

@PE39806

Description

@PE39806

Is your feature request related to a problem? Please describe.

Implementation of BaseFileScanningConnector's scan method should have and use a configurable timeout option in case the service becomes unresponsive which would currently cause a scan to hang indefinitely.

Describe the solution you would like

Add a new connectors.fileScanners.scanTimeout: number value config.ts, used to control the maximum number of seconds that a scan should be awaited before timing out.
A possible implementation for the scan implentation(s) could be:

function delay(ms: number) {
   return new Promise((_, reject) => {
      setTimeout(() => reject(new Error('Timeout exceeded')), ms);
   });
}

// ...

await Promise.race([delay(config.connectors.fileScanners.scanTimeout * 1000), someScanFunction()]);

Describe alternatives you have considered

An alternative to the above could be to add a new BaseFileScanningConnector._scan method and change BaseFileScanningConnector.scan to call this e.g.

function delay(ms: number) {
   return new Promise((_, reject) => {
      setTimeout(() => reject(new Error('Timeout exceeded')), ms);
   });
}
// ...

export abstract class BaseFileScanningConnector {
  async scan(file: FileInterface): Promise<FileScanResult[]> {
    return await Promise.race([delay(config.connectors.fileScanners.scanTimeout * 1000), this._scan(file)]);
  }
  abstract _scan(file: FileInterface): Promise<FileScanResult[]>

  //...
}

However we do not currently enforce scan to be async so I am unsure on this approach in case there are synchronous BaseFileScanningConnector implementaitons.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions