Skip to content

Commit 11e815e

Browse files
committed
Do not interfere with synchronization of callbacks map
1 parent 803f146 commit 11e815e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/mercury/MercuryClient.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public final class MercuryClient extends PacketsManager {
3131
private static final int MERCURY_REQUEST_TIMEOUT = 3000;
3232
private final AtomicInteger seqHolder = new AtomicInteger(1);
3333
private final Map<Long, Callback> callbacks = Collections.synchronizedMap(new HashMap<>());
34+
private final Object removeCallbackLock = new Object();
3435
private final List<InternalSubListener> subscriptions = Collections.synchronizedList(new ArrayList<>());
3536
private final Map<Long, BytesArrayList> partials = new HashMap<>();
3637

@@ -213,8 +214,8 @@ protected void handle(@NotNull Packet packet) throws InvalidProtocolBufferExcept
213214
LOGGER.warn(String.format("Skipped Mercury response, seq: %d, uri: %s, code %d", seq, header.getUri(), header.getStatusCode()));
214215
}
215216

216-
synchronized (callbacks) {
217-
callbacks.notifyAll();
217+
synchronized (removeCallbackLock) {
218+
removeCallbackLock.notifyAll();
218219
}
219220
} else {
220221
LOGGER.warn(String.format("Couldn't handle packet, seq: %d, uri: %s, code %d", seq, header.getUri(), header.getStatusCode()));
@@ -253,9 +254,9 @@ public void close() {
253254
if (callbacks.isEmpty()) {
254255
break;
255256
} else {
256-
synchronized (callbacks) {
257+
synchronized (removeCallbackLock) {
257258
try {
258-
callbacks.wait(100);
259+
removeCallbackLock.wait(100);
259260
} catch (InterruptedException ignored) {
260261
}
261262
}

0 commit comments

Comments
 (0)