-
Notifications
You must be signed in to change notification settings - Fork 2k
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
@uppy/companion-client: prevent preflight race condition #4182
Conversation
that caused double OPTIONS to be sent for each reqeust Also simplify, deduplicate and async/awaitify code and fix lint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
|
||
// todo pull out into core instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core has no knowledge of whether you use Companion or not so I don't think it belongs there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any other place where we can store state about a session that is not per-file, but per Uppy instance? I don't like global variables like this. It will leak memory if companionUrl changes. Although maybe unlikely, what if someone adds some trickery to their companionUrl, where there's a new companionUrl for every upload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this.getPluginState
/this.setPluginState
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, but we would have to send this.getPluginState
and this.setPluginState
into every RequestClient instance. Not sure if that's the cleanest way to do it.
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
feel free to review my last commit, then merge this |
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
| Package | Version | Package | Version | | ---------------------- | ------- | ---------------------- | ------- | | @uppy/angular | 0.5.0 | @uppy/image-editor | 2.1.0 | | @uppy/aws-s3-multipart | 3.1.0 | @uppy/locales | 3.0.4 | | @uppy/companion | 4.1.0 | @uppy/tus | 3.0.5 | | @uppy/companion-client | 3.1.0 | @uppy/utils | 5.1.0 | | @uppy/dashboard | 3.2.0 | uppy | 3.3.0 | - @uppy/companion: change default S3 expiry from 300 to 800 seconds (Merlijn Vos / #4206) - @uppy/dashboard: Single file mode (Artur Paikin / #4188) - @uppy/locales: Fix UZ locale (Merlijn Vos / #4178) - @uppy/utils: update typings for `RateLimitedQueue` (Antoine du Hamel / #4204) - @uppy/aws-s3-multipart: empty the queue when pausing (Antoine du Hamel / #4203) - @uppy/image-editor: add checkered background (Livia Medeiros / #4194) - @uppy/aws-s3-multipart: refactor rate limiting approach (Antoine du Hamel / #4187) - @uppy/companion: send expiry time along side S3 signed requests (Antoine du Hamel / #4202) - @uppy/companion-client: add support for `AbortSignal` (Antoine du Hamel / #4201) - @uppy/companion-client: prevent preflight race condition (Mikael Finstad / #4182) - @uppy/aws-s3-multipart: change limit to 6 (Antoine du Hamel / #4199) - @uppy/utils: add `cause` support for `AbortError`s (Antoine du Hamel / #4198) - meta: Fix bad example for setFileState (Tim Whitney / #4191) - meta: Update code example for getFiles (Tim Whitney / #4189) - meta: Fix issue with outdated comment. (Tim Whitney / #4192) - @uppy/aws-s3-multipart: remove unused `timeout` option (Antoine du Hamel / #4186) - meta: Remove dollar sign from command for easier copy/pasting (Youssef Victor / #4180) - @uppy/aws-s3-multipart,@uppy/tus: fix `Timed out waiting for socket` (Antoine du Hamel / #4177) - meta: Add note about facebook approval (Mikael Finstad / #4172) - meta: add a manual deploy for website (Antoine du Hamel / #4171)
* main: (110 commits) @uppy/aws-s3-multipart: handle slow connections better (#4213) @uppy/companion-client: treat `*` the same as missing header (#4221) @uppy/utils: fix types (#4212) @uppy/companion: send expire info for non-multipart uploads (#4214) docs: fix `allowedMetaFields` documentation (#4216) meta: add more bundlers for automated testing (#4100) @uppy/aws-s3-multipart: Fix typo in url check (#4211) meta: use current version of packages when testing bundlers (#4208) meta: do not use the set-output command in workflows (#4175) Release: uppy@3.3.0 (#4207) Companion: change default S3 expiry from 300 to 800 seconds (#4206) Dashboard: Single file mode (#4188) Fix UZ locale (#4178) @uppy/utils: update typings for `RateLimitedQueue` (#4204) @uppy/aws-s3-multipart: empty the queue when pausing (#4203) image-editor: add checkered background (#4194) @uppy/aws-s3-multipart: refactor rate limiting approach (#4187) @uppy/companion: send expiry time along side S3 signed requests (#4202) @uppy/companion-client: add support for `AbortSignal` (#4201) @uppy/companion-client: prevent preflight race condition (#4182) ...
| Package | Version | Package | Version | | ---------------------- | ------- | ---------------------- | ------- | | @uppy/angular | 0.5.0 | @uppy/image-editor | 2.1.0 | | @uppy/aws-s3-multipart | 3.1.0 | @uppy/locales | 3.0.4 | | @uppy/companion | 4.1.0 | @uppy/tus | 3.0.5 | | @uppy/companion-client | 3.1.0 | @uppy/utils | 5.1.0 | | @uppy/dashboard | 3.2.0 | uppy | 3.3.0 | - @uppy/companion: change default S3 expiry from 300 to 800 seconds (Merlijn Vos / transloadit#4206) - @uppy/dashboard: Single file mode (Artur Paikin / transloadit#4188) - @uppy/locales: Fix UZ locale (Merlijn Vos / transloadit#4178) - @uppy/utils: update typings for `RateLimitedQueue` (Antoine du Hamel / transloadit#4204) - @uppy/aws-s3-multipart: empty the queue when pausing (Antoine du Hamel / transloadit#4203) - @uppy/image-editor: add checkered background (Livia Medeiros / transloadit#4194) - @uppy/aws-s3-multipart: refactor rate limiting approach (Antoine du Hamel / transloadit#4187) - @uppy/companion: send expiry time along side S3 signed requests (Antoine du Hamel / transloadit#4202) - @uppy/companion-client: add support for `AbortSignal` (Antoine du Hamel / transloadit#4201) - @uppy/companion-client: prevent preflight race condition (Mikael Finstad / transloadit#4182) - @uppy/aws-s3-multipart: change limit to 6 (Antoine du Hamel / transloadit#4199) - @uppy/utils: add `cause` support for `AbortError`s (Antoine du Hamel / transloadit#4198) - meta: Fix bad example for setFileState (Tim Whitney / transloadit#4191) - meta: Update code example for getFiles (Tim Whitney / transloadit#4189) - meta: Fix issue with outdated comment. (Tim Whitney / transloadit#4192) - @uppy/aws-s3-multipart: remove unused `timeout` option (Antoine du Hamel / transloadit#4186) - meta: Remove dollar sign from command for easier copy/pasting (Youssef Victor / transloadit#4180) - @uppy/aws-s3-multipart,@uppy/tus: fix `Timed out waiting for socket` (Antoine du Hamel / transloadit#4177) - meta: Add note about facebook approval (Mikael Finstad / transloadit#4172) - meta: add a manual deploy for website (Antoine du Hamel / transloadit#4171)
...that caused double OPTIONS to be sent for each inital reqeust
Also simplify, deduplicate and async/awaitify code and fix lint.
This race condition caused the RequestClient to send X redundant OPTIONS requests immediately when starting an upload, where X is the number of files uploaded. This affected all Companion-related uploads: s3, s3-multipart, google drive etc. Note that after the initial requests, it would not send double OPTIONS (such as multipart uploading individual parts, because it would be cached by then).
This cache would be cleared for every upload "session".
After this PR, we only send OPTIONS once, then wait for the response before continuing. We globally cache the allowed headers based on
companionUrl
, so even in subsequent upload sessions, it will not send any more of these extraneous OPTIONS requeststip for easier review: ignore whitespace