Skip to content
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

feat!: cluster v1.0 support #40

Merged
merged 4 commits into from
Apr 4, 2022
Merged

feat!: cluster v1.0 support #40

merged 4 commits into from
Apr 4, 2022

Conversation

alanshaw
Copy link

@alanshaw alanshaw commented Mar 23, 2022

Support for Cluster v1.0.

There are breaking changes to some API endpoints (they now return ndjson).

BREAKING CHANGE: The client is not compatible with Cluster pre v1.0 anymore.

* @param {BodyInit} [init.body]
* @param {AbortSignal} [init.signal]
*/
const streamRequest = async function* (

Choose a reason for hiding this comment

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

If an error occurs during the stream, we set trailer headers. Is it possible to handle those with JS?

A good example is that cluster is restarted while you are querying something, and then perhaps the data stream is aborted and you get a trailer saying "context cancelled".

The trailer is X-Stream-Error. (at the beginning of the response there is a Trailer: X-Stream-Error header).

Copy link
Author

Choose a reason for hiding this comment

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

AFAIK trailers have always been a problem in "browser" contexts. I'll double check.

Copy link
Author

Choose a reason for hiding this comment

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

Still not supported using fetch mdn/browser-compat-data#14703

Not sure if we really want to go down the XMLHttpRequest route...

Choose a reason for hiding this comment

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

It's not an overly important thing, for your usecase...

Choose a reason for hiding this comment

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

Let's leave track on an issue and move on?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, talking to lidel he doesn't seem to think you can get them out of a XMLHttpRequest either.

(I read something that seemed to suggest you could)

Copy link
Contributor

@olizilla olizilla Mar 30, 2022

Choose a reason for hiding this comment

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

Note that soon our pattern of always set a X-Stream-Error trailer header and maybe send a X-Stream-Error trailer will be treated as an invalid response in nodejs in the next release (>=17.x) unless we get them to change their mind on it.
nodejs/undici#432 (comment)
web3-storage/web3.storage#1017

@alanshaw alanshaw marked this pull request as ready for review March 24, 2022 12:20
@alanshaw alanshaw changed the title feat: cluster v1.0 support feat!: cluster v1.0 support Mar 24, 2022
buffer += decoder.decode(result.value, { stream: true })
const parts = buffer.split(matcher)
buffer = parts.pop() || ''
for (const part of parts) yield JSON.parse(part)

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I based it on iterable-ndjson which looks almost identical. However that takes an AsyncIterable and we have a ReadableStream (which is not yet async iterable in the browser)

@hsanjuan
Copy link

hsanjuan commented Mar 30, 2022 via email

Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

Nice. Questions and typo fix suggestion are inline.

src/index.js Outdated
throw new Error('response data is not an array')
const statuses = []
for await (const d of stream) {
statuses.push(toStausResponse(d))
Copy link
Contributor

Choose a reason for hiding this comment

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

Not from this PR, but wat is Staus?

Suggested change
statuses.push(toStausResponse(d))
statuses.push(toStatusResponse(d))

src/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

👍

@olizilla
Copy link
Contributor

olizilla commented Apr 4, 2022

We could always set it too, but leave it empty.

@hsanjuan that's a good idea. First I'm gonna see if we can get any movement on changing the http client in node. It's no landed in a LTS node yet.

@alanshaw alanshaw merged commit fd965ad into main Apr 4, 2022
@alanshaw alanshaw deleted the feat/cluster-v1.0-support branch April 4, 2022 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants