Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbortController doesn't work in Electron #60

Open
MatteoGioioso opened this issue Oct 13, 2023 · 0 comments
Open

AbortController doesn't work in Electron #60

MatteoGioioso opened this issue Oct 13, 2023 · 0 comments

Comments

@MatteoGioioso
Copy link

MatteoGioioso commented Oct 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant