Skip to content

Fix request cancellation#552

Merged
julien-nc merged 2 commits intomasterfrom
fix/548/undefined-error-attrs-when-cancel
Dec 12, 2022
Merged

Fix request cancellation#552
julien-nc merged 2 commits intomasterfrom
fix/548/undefined-error-attrs-when-cancel

Conversation

@julien-nc
Copy link
Contributor

closes #548

Some error attrs are not defined when a request is canceled (with AbortController or CancelToken).

…anceled

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc julien-nc added bug Something isn't working 3. to review labels Dec 8, 2022
@ChristophWurst
Copy link
Contributor

Mind adding a simple unit test to cover this?

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc
Copy link
Contributor Author

@ChristophWurst Sure, is this enough?

Copy link

@danxuliu danxuliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested (in Talk) and works 👍

Just a little detail, should config and headers be guarded against undefined values when used in the if conditions? For example, in: https://github.com/nextcloud/nextcloud-axios/blob/b1bf15b5097f702fd43f3b365c7fd75dae262fc8/lib/interceptors/maintenance-mode.ts#L17-L20

I guess that it would not be needed, as if status is set to a numeric value then error probably contains also the other expected values, but I do not know if that is guaranteed :-)

@julien-nc julien-nc merged commit 4065b1d into master Dec 12, 2022
@delete-merged-branch delete-merged-branch bot deleted the fix/548/undefined-error-attrs-when-cancel branch December 12, 2022 12:52
@julien-nc
Copy link
Contributor Author

I guess that it would not be needed, as if status is set to a numeric value then error probably contains also the other expected values, but I do not know if that is guaranteed :-)

@danxuliu Yeah not sure an extra check is needed if we know the status is numeric. We can make it safer later after having faced new crashes 😁.

expect(token.token).not.toBe(undefined)
})

it('intercepting a cancellation error', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi jest tests should be phrased like english sentences starting with it. E.g. it intercepts a cancellation error. That makes the outputs human readable. ref https://jestjs.io/docs/api#testname-fn-timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right thanks. Will fix this.

And what about the test content? Are you fine with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that looks fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I may be nitpicky then it would be better if the tests were moved to the individual test suites for the modules

@nickvergessen
Copy link
Contributor

This seems to break talks long polling as it automatically aborts now after 10 seconds, instead of waiting for the 30s response

@julien-nc
Copy link
Contributor Author

@nickvergessen I'm not sure this change can have an effect on the request timeout. It only affects how errors are handled once an error happens.
@ChristophWurst What do you think?

@nickvergessen
Copy link
Contributor

I downgraded to 2.1.0 of this lib and now it works again.

Seems the problem is from CancelableRequests:
https://github.com/nextcloud/spreed/blob/516d50836a333b146e70c2f8ab1abe6564fa8328/src/store/messagesStore.js#L850

@nickvergessen
Copy link
Contributor

Hmm downgrading didn't fix. I forgot to revert decreasing the timeout on PHP level.
So not sure, but lets continue in #579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"error.request is undefined" when a request is cancelled

4 participants