-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add http.asyncRequest
#2825
Comments
Merged
mstoykov
added a commit
that referenced
this issue
Jan 26, 2023
This is implementation of http.request but it return a promise and does all the networking off the event loop. The code is pretty simple and seems fairly safe given that most possible race conditions would also happen in the case of `http.batch`. Even with that there is at least one test that previously couldn't have happened with http.batch. closes #2825
mstoykov
added a commit
that referenced
this issue
Jan 26, 2023
This is implementation of http.request, but it returns a promise and does all the networking off the event loop. The code is pretty simple and seems fairly safe given that most possible race conditions would also happen in the case of `http.batch`. Even with that there is at least one test that previously couldn't have happened with http.batch. closes #2825
Merged
mstoykov
added a commit
that referenced
this issue
Jan 26, 2023
This is implementation of http.request, but it returns a promise and does all the networking off the event loop. The code is pretty simple and seems fairly safe given that most possible race conditions would also happen in the case of `http.batch`. Even with that there is at least one test that previously couldn't have happened with http.batch. closes #2825
mstoykov
added a commit
that referenced
this issue
Jan 27, 2023
This is implementation of http.request, but it returns a promise and does all the networking off the event loop. The code is pretty simple and seems fairly safe given that most possible race conditions would also happen in the case of `http.batch`. Even with that there is at least one test that previously couldn't have happened with http.batch. closes #2825
mstoykov
added a commit
that referenced
this issue
Jan 31, 2023
This is implementation of http.request, but it returns a promise and does all the networking off the event loop. The code is pretty simple and seems fairly safe given that most possible race conditions would also happen in the case of `http.batch`. Even with that there is at least one test that previously couldn't have happened with http.batch. closes #2825
mstoykov
added a commit
that referenced
this issue
Feb 1, 2023
This is implementation of http.request, but it returns a promise and does all the networking off the event loop. The code is pretty simple and seems fairly safe given that most possible race conditions would also happen in the case of `http.batch`. Even with that there is at least one test that previously couldn't have happened with http.batch. closes #2825
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Description
With the addition of event loop months ago, k6 did get the ability to have asynchronous operations, like all the other js tools ;).
While we have added some experimental APIs and will likely add more that use this there is a small problem.
Using asynchronous APIs in combination with synchronous ones that take long time will block the event loop. Which will prevent the asynchronous calls from completing.
This will effectively not log a single message until all the http requests are finished. This might take a few minutes. If the websocket was supposed to return something back there is a very good chance the server would've timeouted this connection.
In order for this to not be the case we need asynchronous http call.
While getting the new-http API will be best this is unlikely to happen soon so a stop gap solution seems like a good middle ground.
Suggested Solution (optional)
Implement
asyncRequest
with the same signature asrequest
but instead of returning the response directly, it will return a Promise that will be resolved with the response or rejected with an error in the same cases ashttp.request
would do it.No other changes are at this point proposed including:
http.asyncGet
,http.asyncPost
and friends. While they might be slightly easier to write, there are already confusion about which have bodies and which not and arguably are saving very small amount of writing.http.asyncBatch
- given thathttp.batch
is mostly used to do multiple requests at the same time it seems less useful to have this in the case that you can just make a bunch ofasyncRequest
s andPromise.all
on them for example.The above might change, although the hope is that this will reduce the maintenance burden, while still giving enough functionality to users until the new http API lands.
Already existing or connected issues / PRs (optional)
No response
The text was updated successfully, but these errors were encountered: