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

[FIXED] JetStream: do not send acks for js_AckNone subscriptions #495

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,9 @@ natsConn_processMsg(natsConnection *nc, char *buf, int bufLen)
{
bool signal= false;

if ((jsi != NULL) && jsi->ackNone)
natsMsg_setAcked(msg);

if (sub->msgList.msgs > sub->msgsMax)
sub->msgsMax = sub->msgList.msgs;

Expand Down
3 changes: 2 additions & 1 deletion src/js.c
Original file line number Diff line number Diff line change
Expand Up @@ -2060,9 +2060,10 @@ _subscribe(natsSubscription **new_sub, jsCtx *js, const char *subject, const cha
jsi->pull = isPullMode;
jsi->ordered= opts->Ordered;
jsi->dseq = 1;
jsi->ackNone= opts->Config.AckPolicy == js_AckNone;
js_retain(js);

if ((usrCB != NULL) && !opts->ManualAck && (opts->Config.AckPolicy != js_AckNone))
if ((usrCB != NULL) && !opts->ManualAck && !jsi->ackNone)
{
// Keep track of user provided CB and closure
jsi->usrCb = usrCB;
Expand Down
1 change: 1 addition & 0 deletions src/natsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ typedef struct __jsSub
bool pull;
bool ordered;
bool dc; // delete JS consumer in Unsub()/Drain()
bool ackNone;

int64_t hbi;
int64_t active;
Expand Down
29 changes: 29 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24098,6 +24098,7 @@ test_JetStreamSubscribeSync(void)
const char *consName;
jsConsumerInfo *ci = NULL;
jsMsgMetaData *meta = NULL;
jsSubOptions so;

JS_SETUP(2, 3, 5);

Expand Down Expand Up @@ -24493,6 +24494,34 @@ test_JetStreamSubscribeSync(void)
IFOK(s, natsSubscription_WaitForDrainCompletion(sub, 1000));
testCond(s == NATS_OK);

natsSubscription_Destroy(sub);
sub = NULL;

test("Create sub with ack-none: ");
jsSubOptions_Init(&so);
so.Config.AckPolicy = js_AckNone;
so.Config.DeliverPolicy = js_DeliverLast;
s = js_SubscribeSync(&sub, js, "foo", NULL, &so, &jerr);
testCond((s == NATS_OK) && (sub != NULL) && (jerr == 0));

test("Check msg received: ");
msg = NULL;
s = natsSubscription_NextMsg(&msg, sub, 1000);
testCond(s == NATS_OK);

test("Check ack: ");
s = natsMsg_InProgress(msg, NULL);
IFOK(s, natsMsg_Nak(msg, NULL));
IFOK(s, natsMsg_Ack(msg, NULL));
IFOK(s, natsMsg_Term(msg, NULL));
testCond(s == NATS_OK);

test("Check no ack sent: ");
natsMsg_Destroy(msg);
msg = NULL;
s = natsSubscription_NextMsg(&msg, ackSub, 100);
testCond((s == NATS_TIMEOUT) && (msg == NULL));

natsSubscription_Destroy(sub);
natsSubscription_Destroy(ackSub);
JS_TEARDOWN;
Expand Down