Skip to content

Commit 4e4a148

Browse files
committed
Block up to 1 second for final fire and forget on close
The Mono returned before from the Bean destroyMethod would not be subscribed to, and therefore nothing would happen on destroying the bean. Now we will wait up to 1 second for the fire and forget final scrape to be sent on close. Resolves gh-35
1 parent 1248804 commit 4e4a148

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

client/src/main/java/io/micrometer/prometheus/rsocket/PrometheusRSocketClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,18 @@ public void close() {
150150
}
151151
}
152152

153-
public Mono<Void> pushAndClose() {
153+
public void pushAndClose() {
154154
PublicKey key = latestKey.get();
155155
if (key != null) {
156156
try {
157-
return sendingSocket
157+
sendingSocket
158158
.fireAndForget(scrapePayload(key))
159-
.then(Mono.fromRunnable(this::close));
159+
.block(Duration.ofSeconds(1));
160160
} catch (Exception ignored) {
161161
// give up, we tried...
162162
}
163163
}
164-
return Mono.fromRunnable(this::close);
164+
close();
165165
}
166166

167167
private Payload scrapePayload(@Nullable PublicKey publicKey) throws Exception {

client/src/test/java/io/micrometer/prometheus/rsocket/PrometheusRSocketClientTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public Mono<Void> fireAndForget(Payload payload) {
130130
assertThat(normalScrapeLatch.await(1, TimeUnit.SECONDS)).isTrue();
131131

132132
// trigger dying scrape
133-
client.pushAndClose().block(Duration.ofSeconds(1));
133+
client.pushAndClose();
134134
assertThat(dyingScrapeLatch.await(1, TimeUnit.SECONDS))
135135
.as("Dying scrape (fire-and-forget) should be successfully called")
136136
.isTrue();

client/src/test/java/io/micrometer/prometheus/rsocket/SampleClientThatClosesManually.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public static void main(String[] args) throws InterruptedException {
4848
throw new IllegalStateException("Didn't receive a key within 10 seconds");
4949
}
5050

51-
CountDownLatch closeLatch = new CountDownLatch(1);
52-
client.pushAndClose().subscribe(s -> closeLatch.countDown());
51+
client.pushAndClose();
5352

5453
if (!keyLatch.await(3, TimeUnit.SECONDS)) {
5554
throw new IllegalStateException("Not able to close within 3 seconds");

client/src/test/java/io/micrometer/prometheus/rsocket/SampleServerlessClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void main(String[] args) throws InterruptedException {
4545

4646
Thread.sleep(1000);
4747

48-
client.pushAndClose().block(Duration.ofSeconds(1));
48+
client.pushAndClose();
4949
counts.dispose();
5050
}
5151
}

0 commit comments

Comments
 (0)