Skip to content

Commit 69cc891

Browse files
committed
Avoid deadlock when session is closed
1 parent 3508705 commit 69cc891

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class Session implements Closeable {
8888
private CdnManager cdnManager;
8989
private CacheManager cacheManager;
9090
private String countryCode = null;
91+
private volatile boolean closed = false;
9192

9293
private Session(Inner inner, Socket socket) throws IOException {
9394
this.inner = inner;
@@ -338,6 +339,7 @@ public void close() throws IOException {
338339

339340
apWelcome = null;
340341
cipherPair = null;
342+
closed = true;
341343

342344
LOGGER.info(String.format("Closed session. {deviceId: %s, ap: %s} ", inner.deviceId, conn.socket.getInetAddress()));
343345
}
@@ -347,6 +349,8 @@ private void sendUnchecked(Packet.Type cmd, byte[] payload) throws IOException {
347349
}
348350

349351
private void waitAuthLock() {
352+
if (closed) throw new IllegalStateException("Session is closed!");
353+
350354
synchronized (authLock) {
351355
if (cipherPair == null || authLock.get()) {
352356
try {
@@ -428,11 +432,7 @@ public Authentication.APWelcome apWelcome() {
428432

429433
public boolean valid() {
430434
waitAuthLock();
431-
return apWelcome != null && conn != null && !conn.socket.isClosed();
432-
}
433-
434-
public boolean isConnecting() {
435-
return cipherPair == null || authLock.get();
435+
return apWelcome != null && conn != null && !conn.socket.isClosed() && !closed;
436436
}
437437

438438
@NotNull

0 commit comments

Comments
 (0)