Skip to content

Commit

Permalink
Merge pull request #645 from nats-io/fix_644
Browse files Browse the repository at this point in the history
[FIXED] natsConnection_RequestMsg() incorrectly returns NATS_NO_SERVER_SUPPORT
  • Loading branch information
kozlovic authored Mar 9, 2023
2 parents 39e82d0 + 5111033 commit 7b36d52
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ natsConn_publish(natsConnection *nc, natsMsg *msg, const char *reply, bool direc
// accessing the headers. It should still be considered having headers.
if ((msg->headers != NULL) || natsMsg_needsLift(msg))
{
if (!nc->info.headers)
// Do the check for server's headers support only after we have completed
// the initial connect (we could be here with initc true - that is, initial
// connect in progress - when using natsOptions_SetRetryOnFailedConnect
// option).
if (!nc->initc && !nc->info.headers)
{
natsConn_Unlock(nc);

Expand Down
18 changes: 18 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9530,6 +9530,8 @@ test_RetryOnFailedConnect(void)
int64_t end = 0;
natsThread *t = NULL;
natsSubscription *sub = NULL;
natsMsg *msg = NULL;
natsMsg *rmsg = NULL;
struct threadArg arg;

s = _createDefaultThreadArgsForCbTests(&arg);
Expand Down Expand Up @@ -9596,6 +9598,16 @@ test_RetryOnFailedConnect(void)
testCond((s == NATS_NOT_YET_CONNECTED) && (nc != NULL));
nats_clearLastError();

// Request with a message with headers does timeout as opposed to returning
// the NATS_NO_SERVER_SUPPORT error.
test("Request with message with headers: ");
s = natsMsg_Create(&msg, "request.headers", NULL, "hello", 5);
IFOK(s, natsMsgHeader_Set(msg, "some", "header"));
IFOK(s, natsConnection_RequestMsg(&rmsg, nc, msg, 250));
testCond(s == NATS_TIMEOUT);
nats_clearLastError();
natsMsg_Destroy(msg);

test("Subscription ok: ");
arg.control = 99;
s = natsConnection_Subscribe(&sub, nc, "foo", _recvTestString, (void*)&arg);
Expand Down Expand Up @@ -32662,6 +32674,9 @@ test_StanBasicPublish(void)

stanConnection_Destroy(sc);

if (valgrind)
nats_Sleep(900);

_stopServer(pid);
}

Expand Down Expand Up @@ -32719,6 +32734,9 @@ test_StanBasicPublishAsync(void)

_destroyDefaultThreadArgs(&args);

if (valgrind)
nats_Sleep(900);

_stopServer(pid);
}

Expand Down

0 comments on commit 7b36d52

Please sign in to comment.