Skip to content

Commit a5d5f67

Browse files
dimakubaAndrewKushnir
authored andcommitted
fix(http): avoid abort a request when fetch operation is completed (#37367)
`abort` method is calling, even if fetch operation is completed Fixes #36537 PR Close #37367
1 parent dfb58c4 commit a5d5f67

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/common/http/src/xhr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ export class HttpXhrBackend implements HttpBackend {
339339
}
340340

341341
// Finally, abort the in-flight request.
342-
xhr.abort();
342+
if (xhr.readyState !== xhr.DONE) {
343+
xhr.abort();
344+
}
343345
};
344346
});
345347
}

packages/common/http/test/xhr_spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ const XSSI_PREFIX = ')]}\'\n';
147147
});
148148
factory.mock.mockErrorEvent(new Error('blah'));
149149
});
150+
it('avoids abort a request when fetch operation is completed', done => {
151+
const abort = jasmine.createSpy('abort');
152+
153+
backend.handle(TEST_POST).toPromise().then(() => {
154+
expect(abort).not.toHaveBeenCalled();
155+
done();
156+
});
157+
158+
factory.mock.abort = abort;
159+
factory.mock.mockFlush(200, 'OK', 'Done');
160+
});
150161
describe('progress events', () => {
151162
it('are emitted for download progress', done => {
152163
backend.handle(TEST_POST.clone({reportProgress: true}))

0 commit comments

Comments
 (0)