Skip to content

Commit 0e556f1

Browse files
committed
Ensure DNS errors bubble up as errors in reactive streams
Currently DNS lookups happen synchronously in the reactive streams driver. This isn't good, but with this change at least DNS errors will be properly reported. JAVA-3852
1 parent cf79fa2 commit 0e556f1

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,37 +145,36 @@ public void openAsync(final SingleResultCallback<Void> callback) {
145145
isTrue("Open already called", stream == null, callback);
146146
try {
147147
stream = streamFactory.create(serverId.getAddress());
148-
} catch (Throwable t) {
149-
callback.onResult(null, t);
150-
return;
151-
}
152-
stream.openAsync(new AsyncCompletionHandler<Void>() {
153-
@Override
154-
public void completed(final Void aVoid) {
155-
connectionInitializer.initializeAsync(InternalStreamConnection.this, new SingleResultCallback<ConnectionDescription>() {
156-
@Override
157-
public void onResult(final ConnectionDescription result, final Throwable t) {
158-
if (t != null) {
159-
close();
160-
callback.onResult(null, t);
161-
} else {
162-
description = result;
163-
opened.set(true);
164-
sendCompressor = findSendCompressor(description);
165-
if (LOGGER.isInfoEnabled()) {
166-
LOGGER.info(format("Opened connection [%s] to %s", getId(), serverId.getAddress()));
148+
stream.openAsync(new AsyncCompletionHandler<Void>() {
149+
@Override
150+
public void completed(final Void aVoid) {
151+
connectionInitializer.initializeAsync(InternalStreamConnection.this, new SingleResultCallback<ConnectionDescription>() {
152+
@Override
153+
public void onResult(final ConnectionDescription result, final Throwable t) {
154+
if (t != null) {
155+
close();
156+
callback.onResult(null, t);
157+
} else {
158+
description = result;
159+
opened.set(true);
160+
sendCompressor = findSendCompressor(description);
161+
if (LOGGER.isInfoEnabled()) {
162+
LOGGER.info(format("Opened connection [%s] to %s", getId(), serverId.getAddress()));
163+
}
164+
callback.onResult(null, null);
167165
}
168-
callback.onResult(null, null);
169166
}
170-
}
171-
});
172-
}
167+
});
168+
}
173169

174-
@Override
175-
public void failed(final Throwable t) {
176-
callback.onResult(null, t);
177-
}
178-
});
170+
@Override
171+
public void failed(final Throwable t) {
172+
callback.onResult(null, t);
173+
}
174+
});
175+
} catch (Throwable t) {
176+
callback.onResult(null, t);
177+
}
179178
}
180179

181180
private Map<Byte, Compressor> createCompressorMap(final List<MongoCompressor> compressorList) {

0 commit comments

Comments
 (0)