Skip to content

Support wss protocol for change streamer#4555

Merged
darkgnotic merged 7 commits into
rocicorp:mainfrom
tjenkinson:change-streamer-protocol
Jul 2, 2025
Merged

Support wss protocol for change streamer#4555
darkgnotic merged 7 commits into
rocicorp:mainfrom
tjenkinson:change-streamer-protocol

Conversation

@tjenkinson
Copy link
Copy Markdown
Contributor

@tjenkinson tjenkinson commented Jun 30, 2025

Adds a changeStreamer.protocol (ZERO_CHANGE_STREAMER_PROTOCOL) option, which can be set to wss

Before #4335 we were able to use a https url.

With this change if https is used, the ownerAddress value in the db will have the wss:// suffix. The view syncer will use the protocol in the url if there is one, otherwise default to ws://

I decided to still not write ws:// into the URL in the db to not break existing deployments, as if a new version of the replication manager came up first, an existing view syncer could crash.

Deployed to our staging env and seems to work

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 30, 2025

@tjenkinson is attempting to deploy a commit to the Rocicorp Team on Vercel.

A member of the Team first needs to authorize it.

@tjenkinson tjenkinson changed the title Support https protocol for change streamer [WIP] Support https protocol for change streamer Jun 30, 2025
Adds a `changeStreamer.protocol` (`ZERO_CHANGE_STREAMER_PROTOCOL`) option, which can be set to `https`

Before rocicorp#4335 we were able to use a https url.
@tjenkinson tjenkinson force-pushed the change-streamer-protocol branch from eb1d154 to d905415 Compare June 30, 2025 12:49
@tjenkinson tjenkinson changed the title [WIP] Support https protocol for change streamer Support https protocol for change streamer Jun 30, 2025
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Recommend ignoring whitespace. Wrapped all the existing tests in another describe so can have one for http and the other for https

throw new Error(`no change-streamer is running`);
}
const uri = new URL(path, `http://${address}/`);
const uri = new URL(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not tested currently. Not sure on the best approach given the current tests rely running a local server. Maybe need to start a https server too and disable certificate validation?

@tjenkinson tjenkinson marked this pull request as ready for review June 30, 2025 13:40
const uri = new URL(path, `http://${address}/`);
const uri = new URL(
path,
address.startsWith('http://') || address.startsWith('https://')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe: address.includes("://") so that it takes any scheme/protocol into account? Not that we expect people to use it, but ws:// and wss:// would also be valid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @darkgnotic !

Sure can update tomorrow. Should I allow the others in the config too then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually is http/https even valid for a websocket? Maybe it should be ws/wss?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like really it should be ws/wss but TIL support for http/https was added to support relative urls whatwg/websockets#45 websockets/ws#2162

I also had /^[a-zA-Z0-9+\-.]+:/.test(address) ? `${address}/` : `ws://${address}/`, locally to accept any protocol here, but if the config only accepts ws/wss maybe it's better to be stricter?

await db`UPDATE ${this.#cdc('replicationState')} SET ${db({owner, ownerAddress})}`;
this.#lc.info?.(`assumed ownership at ${ownerAddress}`);
const ownerProtocol = this.#discoveryProtocol;
// we omit `http://` so that old view syncer versions that are not expecting the protocol continue to not get it
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well thought out. Thank you!

@tjenkinson tjenkinson force-pushed the change-streamer-protocol branch from 7554d37 to a7f094e Compare July 1, 2025 08:21
@tjenkinson tjenkinson changed the title Support https protocol for change streamer Support wss protocol for change streamer Jul 1, 2025
@tjenkinson tjenkinson force-pushed the change-streamer-protocol branch from a7f094e to e34bd8e Compare July 1, 2025 08:39
Copy link
Copy Markdown
Contributor

@darkgnotic darkgnotic left a comment

Choose a reason for hiding this comment

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

Thank you @tjenkinson !

Comment thread packages/zero-cache/src/services/change-streamer/storer.ts Outdated
const uri = new URL(path, `http://${address}/`);
const uri = new URL(
path,
address.startsWith('ws://') || address.startsWith('wss://')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Limiting the protocol value to ws and wss in the option definition seems fine, but I would prefer leaving this part to be a scheme agnostic check of includes('://').

Juuust in case something out there depends on the scheme being http. Hopefully nothing does. 🤞

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Although I'm not sure how something else could get into the db?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The idea is that it would be easier to add more options if necessary (fewer places in the code to modify).

Thank you! I'll merge this!

@darkgnotic darkgnotic enabled auto-merge (squash) July 2, 2025 02:20
@darkgnotic darkgnotic merged commit 37268b6 into rocicorp:main Jul 2, 2025
11 of 14 checks passed
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.

2 participants