diff --git a/src/conn.c b/src/conn.c index 376b643d7..390b14e85 100644 --- a/src/conn.c +++ b/src/conn.c @@ -3360,7 +3360,7 @@ _processUrlString(natsOptions *opts, const char *urls) serverUrls = (char**) NATS_CALLOC(count + 1, sizeof(char*)); if (serverUrls == NULL) return NATS_NO_MEMORY; - + if (s == NATS_OK) { urlsCopy = NATS_STRDUP(urls); diff --git a/src/js.c b/src/js.c index 7b3d39880..949d1f3b6 100644 --- a/src/js.c +++ b/src/js.c @@ -842,19 +842,23 @@ _timeoutPubAsync(natsTimer *t, void *closure) while (((pm = js->pmHead) != NULL) && (pm->deadline <= now)) { - natsMsg *m = NULL; - - if (natsMsg_Create(&m, pm->subject, NULL, NULL, 0) != NATS_OK) - break; - - natsMsg_setTimeout(m); + // Check if the corresponding message is still in the hashtable. + char *id = (pm->subject+js->rpreLen); + if (natsStrHash_Get(js->pm, id) != NULL) + { + natsMsg *m = NULL; - // Best attempt, ignore NATS_SLOW_CONSUMER errors which may be returned - // here. - nats_lockSubAndDispatcher(js->rsub); - natsSub_enqueueUserMessage(js->rsub, m); - nats_unlockSubAndDispatcher(js->rsub); + if (natsMsg_Create(&m, pm->subject, NULL, NULL, 0) == NATS_OK) + { + natsMsg_setTimeout(m); + // Best attempt, ignore NATS_SLOW_CONSUMER errors which may be returned here. + nats_lockSubAndDispatcher(js->rsub); + natsSub_enqueueUserMessage(js->rsub, m); + nats_unlockSubAndDispatcher(js->rsub); + } + } + // Remove from the list. js->pmHead = pm->next; _destroyPMInfo(pm); }