diff --git a/nostr-java-api/pom.xml b/nostr-java-api/pom.xml index 99b6bfa7..c737fb97 100644 --- a/nostr-java-api/pom.xml +++ b/nostr-java-api/pom.xml @@ -108,6 +108,7 @@ uk.org.lidalia slf4j-test + 2.4.0 test diff --git a/nostr-java-api/src/main/java/nostr/api/WebSocketClientHandler.java b/nostr-java-api/src/main/java/nostr/api/WebSocketClientHandler.java index 53f73e4f..260b92aa 100644 --- a/nostr-java-api/src/main/java/nostr/api/WebSocketClientHandler.java +++ b/nostr-java-api/src/main/java/nostr/api/WebSocketClientHandler.java @@ -61,7 +61,7 @@ protected WebSocketClientHandler( clientFactory); } - WebSocketClientHandler( + public WebSocketClientHandler( @NonNull String relayName, @NonNull RelayUri relayUri, @NonNull SpringWebSocketClient eventClient, @@ -153,6 +153,7 @@ private AutoCloseable openSubscription( "Subscription closed by relay %s for id %s" .formatted(relayName, subscriptionId.value())))); } catch (IOException e) { + errorListener.accept(e); throw new RuntimeException("Failed to establish subscription", e); } } @@ -180,9 +181,9 @@ public void close() throws IOException { AutoCloseable closeFrameHandle = openCloseFrame(subscriptionId, accumulator); closeQuietly(closeFrameHandle, accumulator); closeQuietly(delegate, accumulator); + closeQuietly(client, accumulator); requestClientMap.remove(subscriptionId); - closeQuietly(client, accumulator); accumulator.rethrowIfNecessary(); } diff --git a/nostr-java-api/src/test/java/nostr/api/integration/support/FakeWebSocketClient.java b/nostr-java-api/src/test/java/nostr/api/integration/support/FakeWebSocketClient.java index 2892631a..af405c23 100644 --- a/nostr-java-api/src/test/java/nostr/api/integration/support/FakeWebSocketClient.java +++ b/nostr-java-api/src/test/java/nostr/api/integration/support/FakeWebSocketClient.java @@ -74,12 +74,13 @@ public AutoCloseable subscribe( throws IOException { Objects.requireNonNull(messageListener, "messageListener"); Objects.requireNonNull(errorListener, "errorListener"); + sentPayloads.add(requestJson); if (!open) { - throw new IOException("WebSocket session is closed for " + relayUrl); + log.debug("Subscription on closed WebSocket for {}, returning no-op handle", relayUrl); + return () -> {}; // No-op handle since client is already closed } String id = UUID.randomUUID().toString(); listeners.put(id, new Listener(messageListener, errorListener, closeListener)); - sentPayloads.add(requestJson); return () -> listeners.remove(id); } diff --git a/pom.xml b/pom.xml index c6811016..e0600919 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.tcheeric nostr-java - 0.6.5-SNAPSHOT + 0.6.6-SNAPSHOT pom ${project.artifactId}