Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.4.12 ##
* Core: fixed ready watcher invocation on discovery error

## 2.4.11 ##
* Table: fixed StackOverflow problem for the immediately released sessions

Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/tech/ydb/core/impl/YdbTransportImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ public void startAsync(Runnable readyWatcher) {
discovery.start();
if (readyWatcher != null) {
scheduler.execute(() -> {
discovery.waitReady(-1);
readyWatcher.run();
try {
discovery.waitReady(-1);
} catch (RuntimeException ex) {
logger.warn("Discovery failed during async transport initialization", ex);
} finally {
readyWatcher.run();
}
});
}
}
Expand Down
28 changes: 28 additions & 0 deletions core/src/test/java/tech/ydb/core/impl/YdbTransportImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ public void asyncBuildGoodTest() {
Assert.assertTrue(isReady.isDone());
}

@Test
public void asyncBuildDiscoveryErrorTest() {
MockedScheduler scheduler = new MockedScheduler(MockedClock.create(ZoneId.of("UTC")));

Mockito.when(discoveryChannel.newCall(Mockito.eq(DiscoveryServiceGrpc.getListEndpointsMethod()), Mockito.any()))
.thenReturn(MockedCall.unavailable());

CompletableFuture<Void> isReady = new CompletableFuture<>();

@SuppressWarnings("deprecation")
GrpcTransport transport = GrpcTransport.forConnectionString("grpc://mocked:2136/local")
.withSchedulerFactory(() -> scheduler)
.withDiscoveryTimeout(Duration.ofMillis(100))
.withChannelFactoryBuilder(builder -> channelFactory)
.buildAsync(() -> isReady.complete(null));

Assert.assertNotNull(transport);
Assert.assertFalse(isReady.isDone());

// Run discovery task and ready-watcher task
scheduler.hasTasksCount(2).runNextTask().runNextTask();

// readyWatcher must be called even if discovery fails
Assert.assertTrue(isReady.isDone());

transport.close();
}

@Test
@SuppressWarnings("SleepWhileInLoop")
public void asyncWaitingForReadyTest() throws Exception {
Expand Down