Skip to content

Commit a7f40d8

Browse files
authored
Edit lock don't unlock if was not locked. (#1255)
1 parent 2175501 commit a7f40d8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/io/nats/client/impl/MessageQueue.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ boolean push(NatsMessage msg) {
141141

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

170+
lockWasSuccessful = true;
171+
169172
if (!internal && this.discardWhenFull) {
170173
return this.queue.offer(msg);
171174
}
@@ -184,7 +187,9 @@ boolean push(NatsMessage msg, boolean internal) {
184187
return false;
185188
}
186189
finally {
187-
editLock.unlock();
190+
if (lockWasSuccessful) {
191+
editLock.unlock();
192+
}
188193
}
189194
}
190195

0 commit comments

Comments
 (0)