Perform occurrence POST write async #1037
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the change
There are concerns that when sending an occurrence, the write of the POST request payload can be blocked, blocking the caller. This is specifically about the request write not completing, not about any delay or timeout related to the response, which is already async.
While the http response completes async, the request is performed on the caller's thread. There are concerns that the caller could be blocked in some cases.
This PR uses a zero setTimeout to get off the caller's tick before making the request. This PR also updates all tests that relied on the request being synchronous. (Typically tests that inspect the request.)
Notes:
This PR adheres to this project's es5 syntax.
The execution is kept synchronous until the payload is fully constructed. Making these paths async would cause an undesired change in behavior where objects such as custom data would change value before being evaluated for the payload.
If the subsequent network write blocks the event loop, that may still lead to a perf impact, but that is outside the scope of this PR.
Type of change
Related issues
Fixes: https://app.shortcut.com/rollbar/story/112245
Fixes: #1036
Development
Code review