s3-sync-client icon indicating copy to clipboard operation
s3-sync-client copied to clipboard

AbortController doesn't work in Electron

Open MatteoGioioso opened this issue 1 year ago • 0 comments

Hello and thanks for this library.

I am trying to use the abort controller, but it does not seems to work.

Ubuntu: 20.4
Node: v18.15.0

"s3-sync-client": "^4.3.1"
"@aws-sdk/abort-controller": "^3.374.0"
"electron": "^26.2.1"
"react": "^18.2.0",
"react-dom": "^18.2.0",

I must admit is not the simplest of the setup, but I basically install an even listener into my sync function that listen for the abort event which is triggered on the react UI by pressing a button. The callback gets called successfully, however the transfer monitor does not stop and the upload continues.

According to aws docs it should throw an error as well: https://aws.amazon.com/blogs/developer/abortcontroller-in-modular-aws-sdk-for-javascript/, but in my case it does not.

This is the snippet of my code

  public async sync(
    progressCallback: () => void,
  ): Promise<void> {
    const s3Client = new S3Client({});
    const syncClient = new S3SyncClient({ client: s3Client });

    const opts =  {
      partSize: 100 * 1024 * 1024
    };

    const abortController = new AbortController();
    const monitor = new TransferMonitor();
    const abortCallback = () => {
      console.log('aborting sync')
      abortController.abort();
    }

    monitor.on('progress', progressCallback);
    ipcMain.once('abort', abortCallback);

    try {
      await syncClient.sync(
        localFolder,
        s3Folder,
        { monitor: monitor, abortSignal: abortController.signal, ...opts }
      );
    } catch (e: any) {
      if (e.name === 'AbortError') {
        // Do nothing
      }
      throw e
    } finally {
      monitor.removeListener('progress', progressCallback);
    }
  }

Any idea of what I might be doing wrong? Thanks

MatteoGioioso avatar Oct 13 '23 06:10 MatteoGioioso