Skip to content

Commit

Permalink
Edit lock don't unlock if was not locked. (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Nov 22, 2024
1 parent 2175501 commit a7f40d8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/io/nats/client/impl/MessageQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ boolean push(NatsMessage msg) {

boolean push(NatsMessage msg, boolean internal) {
long start = System.currentTimeMillis();
boolean lockWasSuccessful = false;
try {
/*
This was essentially a Head-Of-Line blocking problem.
Expand All @@ -166,6 +167,8 @@ boolean push(NatsMessage msg, boolean internal) {
throw new IllegalStateException(OUTPUT_QUEUE_IS_FULL + queue.size());
}

lockWasSuccessful = true;

if (!internal && this.discardWhenFull) {
return this.queue.offer(msg);
}
Expand All @@ -184,7 +187,9 @@ boolean push(NatsMessage msg, boolean internal) {
return false;
}
finally {
editLock.unlock();
if (lockWasSuccessful) {
editLock.unlock();
}
}
}

Expand Down

0 comments on commit a7f40d8

Please sign in to comment.