Skip to content

Commit

Permalink
[FIX] added check on fetch for use of max_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jun 6, 2022
1 parent 13c518a commit 88ae3b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions nats-base-client/jsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ export class JetStreamClientImpl extends BaseApiClient
const args: Partial<PullOptions> = {};
args.batch = opts.batch || 1;
if (max_bytes) {
const fv = this.nc.protocol.features.get(Feature.JS_PULL_MAX_BYTES);
if (!fv.ok) {
throw new Error(
`max_bytes is only supported on servers ${fv.min} or better`,
);
}
args.max_bytes = max_bytes;
}
args.no_wait = opts.no_wait || false;
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Features {
this.features = new Map<Feature, FeatureVersion>();
this.server = v;

this.set(Feature.JS_PULL_MAX_BYTES, "2.8.5");
this.set(Feature.JS_PULL_MAX_BYTES, "2.8.3");
}

set(f: Feature, requires: string) {
Expand Down
6 changes: 3 additions & 3 deletions tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,12 @@ Deno.test("basics - server version", async () => {
const { ns, nc } = await setup({});
const nci = nc as NatsConnectionImpl;
assertEquals(nci.protocol.features.require("3.0.0"), false);
assertEquals(nci.protocol.features.require("2.8.3"), true);
assertEquals(nci.protocol.features.require("2.8.2"), true);

const ok = nci.protocol.features.require("2.8.5");
const ok = nci.protocol.features.require("2.8.3");
const bytes = nci.protocol.features.get(Feature.JS_PULL_MAX_BYTES);
assertEquals(ok, bytes.ok);
assertEquals(bytes.min, "2.8.5");
assertEquals(bytes.min, "2.8.3");
assertEquals(ok, nci.protocol.features.supports(Feature.JS_PULL_MAX_BYTES));

await cleanup(ns, nc);
Expand Down
2 changes: 1 addition & 1 deletion tests/jetstream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3463,7 +3463,7 @@ Deno.test("jetstream - pull consumer max_bytes rejected on old servers", async (
sub.pull({ expires: 2000, max_bytes: 2 });
},
Error,
"max_bytes is only supported on servers 2.8.5 or better",
"max_bytes is only supported on servers 2.8.3 or better",
);

await cleanup(ns, nc);
Expand Down

0 comments on commit 88ae3b1

Please sign in to comment.